本文介绍了不正确配置:包含的urlconf< project> .urls中没有任何模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django(1.6.x)项目运行良好的开发服务器,但在Apache2(2.2.22.1)和mod_wsgi(3.3-4)在Ubuntu 12.04.3错误



不正确的配置:包含的urlconf erp.urls没有任何模式



我不明白为什么会这样使用开发服务器,但不是Apache2 / mod_wsgi,我发现难以追踪错误来自哪里。



还有一些其他的SO问题类似的,但唯一的地方我使用反向(一个问题以前发现)是在我的模型中的get_absolute_url - 这应该是好的?



项目设置了一个二Scoops风格,特别是布局是:



< repository_root> /< django_project_root> /< configuration_root> /



其中转换为:



erp_root / erp / erp / code>



,设置为



erp_roo t / erp / erp / settings / * py (包括 __ init __。py



从django.conf.urls导入模式,p> erp / urls.py;

  ,include,url 
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^ $' 'django.contrib.auth.views.login',{'template_name':'login.html'}),
url(r'^ admin /',include(admin.site.urls)),
url(r'^ login / $','django.contrib.auth.views.login',{'template_name':'login.html'},name ='login'),
url '^ logout / $','django.contrib.auth.views.logout_then_login',{},name ='logout'),
url(r'^ search /',include('haystack.urls') ),
url(r'^ inventory /',include('inventory.urls')),


如果settings.DEBUG:
import debug_toolbar
urlpatterns + = patterns('',
url(r'^ __ debug __ /',include(debu g_toolbar.urls)),

和inventory / urls.py:


  from django.conf.urls import url,pattern 
from .forms import CarrierWizardForm1,CarrierWizardForm2,MovementWizardForm1,MovementWizardForm2
从。导入视图

carrier_wizard_forms = [CarrierWizardForm1,CarrierWizardForm2]
movement_wizard_forms = [MovementWizardForm1,MovementWizardForm2]

urlpatterns = patterns('',
url '^ $',views.PartNumberListView.as_view(),name ='inventory_list_index'),
url(r'^ parttype / $',views.part_type_list,name ='index'),
url (r'^ parttype /(?P< parttype> \d {2})/ $',views.part_type_view,name ='part_type_view'),
url(r'^ partnumber / $' PartNumberListView.as_view(),name ='partnumber_list'),
url(r'^ partnumber / add / $',views.PartNumberCreateView.as_view(),name ='partnumber_add'),
url r'^ partnumber /(?P< slug> [ - \w] +)/ $',views.PartNumberView.as_view(),name ='partnumber_view'),
url(r'^ partnumber /( ?P< slug> [ - \w] +)/ update / $',views.PartNumberUpdateView.as_view(),name ='partnumber_update'),
url(r'^ partnumber /(?P< slug& ; [ - \\ w] +)/ delete / $',views.PartNumberDeleteView.as_view(),name ='partnumber_delete'),
....

和erp / settings / dev.py:

 #Django设置为erp项目。 
#settings.py

从unipath导入路径

PROJECT_DIR =路径(__文件__)祖先(3)
MEDIA_ROOT = PROJECT_DIR.child(媒体)
STATIC_ROOT = PROJECT_DIR.child(static)
STATICFILES_DIRS =(
PROJECT_DIR.child(assets),

TEMPLATE_DIRS =(
PROJECT_DIR.child(templates),



DEBUG = True
TEMPLATE_DEBUG = DEBUG

TIME_ZONE ='澳大利亚/墨尔本'
LANGUAGE_CODE ='en-au'
SITE_ID = 1
USE_TZ = True

DATE_FORMAT ='d / m / y'
SHORT_DATE_FORMAT ='d / m / y'

#处理从MEDIA_ROOT提供的媒体的URL。确保使用
#尾部斜线。
#示例:http://example.com/media/,http://media.example.com/
MEDIA_URL =''

#绝对目录静态文件的路径应该被收集到。
#不要把任何东西放在这个目录下;在应用程序的static /子目录和STATICFILES_DIRS中存储静态文件
#。
#示例:/var/www/example.com/static/
STATIC_ROOT =''

#静态文件的URL前缀。
#示例:http://example.com/static/,http://static.example.com/
STATIC_URL ='/ static /'

STATICFILES_FINDERS =(
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',


#知道如何从各种来源导入模板的可调用列表。
TEMPLATE_LOADERS =(
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',


MIDDLEWARE_CLASSES =(
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'堡垒。中间件.LoginRequiredMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',


ROOT_URLCONF ='erp.urls'

#Python Django的runserver使用的WSGI应用程序路径。
WSGI_APPLICATION ='erp.wsgi.application'


INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib.contenttypes ',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles'
'django.contrib.admin',
'django.contrib.formtools',
'django.contrib.humanize',
'inventory',
'django_extensions ',
'extra_views',
'debug_toolbar',
'django_tables2',
'forthold',
'bootstrap3',
'haystack'


LOGIN_URL ='/ login'
LOGOUT_URL ='/ logout'

#对于Stronghold
STRONGHOLD_PUBLIC_NAMED_URLS =(
'login',
'logout',


#这是调试工具栏中间件需要
INTERNAL_IPS =('192.168.0.16','0.0 .0.0' , '127.0.0.1', :: 1','192.168.0.115')

#这是由django_tables2
TEMPLATE_CONTEXT_PROCESSORS =(django.contrib.auth.context_processors.auth,
django
django.core.context_processors.i18n,
django.core.context_processors.media,
django.core.context_processors.static
django.core.context_processors.tz,
django.contrib.messages.context_processors.messages,
django.core.context_processors.request

$

LOGIN_REDIRECT_URL ='/ inventory /'

DEBUG_TOOLBAR_​​PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar。 panel.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.head ers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging。 LoggingPanel',
]

def show_toolbar(request):
return True#总是显示工具栏,例如目的。

DEBUG_TOOLBAR_​​CONFIG = {
'INTERCEPT_REDIRECTS':False,
'INSERT_BEFORE':'< / body>',
'ENABLE_STACKTRACES':True,
}

#这是Haystack所需的 - 搜索引擎
HAYSTACK_CONNECTIONS = {
'default':{
'ENGINE':'haystack.backends.solr_backend .SolrEngine',
'URL':'http://127.0.0.1:8085/solr/erp',
},
}

我的wsgi是小型设置mod的标准:

  import os 
os.environ.setdefault(DJANGO_SETTINGS_MODULE,erp.settings.settings)
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

我的apache2 / sites-avail / erp.conf是:

 < VirtualHost *:80> 
ServerName deverp
ServerAdmin管理员
DocumentRoot / path / www / dev / erp / erp /
ErrorLog /var/log/apache2/dev/error.log
CustomLog /var/log/apache2/dev/access.log组合
WSGIDaemonProcess deverp python-path = / path / www / dev / erp / erp:/path/.virtualenvs/erp-dev/lib/python2.7/ site-packages
WSGIProcessGroup deverp
WSGIScriptAlias / /path/www/dev/erp/erp/erp/wsgi.py
<目录/路径/ www / dev / erp / erp / erp> ;
<文件wsgi.py>
订单拒绝,允许
允许从所有
< / Files>
< / Directory>
< / VirtualHost>


解决方案

所以,我实际遇到了类似的问题。在您发布的问题后,巧合的是。实际上这个问题是由于django-debug-toolbar中缺少一个设置。



你所缺少的设置是:

  DEBUG_TOOLBAR_​​PATCH_SETTINGS = False 

它将与runserver一起工作,但是如果您尝试使用honcho,or gunicorn或其他任何使用WSGI接口的程序来运行它,则会爆炸。



希望这有帮助!



编辑:如以下@japhyr所述,它有助于查看明确设置说明:


I have a django (1.6.x) project that runs fine with the dev server, but is failing under Apache2 (2.2.22.1) and mod_wsgi (3.3-4) on Ubuntu 12.04.3 with the error

ImproperlyConfigured: The included urlconf erp.urls doesn't have any patterns in it

I don't understand why it would work with the dev server but not Apache2/mod_wsgi and I'm finding it difficult to track down where the error is coming from.

There are a number of other SO questions similar, but the only place I use reverse (one problem previously found) is in get_absolute_url in my models - this should be fine?

The project is set up a la Two Scoops style, in particular the layout is:

<repository_root>/<django_project_root>/<configuration_root>/

which translates to:

erp_root/erp/erp/

and the settings are

erp_root/erp/erp/settings/*py (including the __init__.py)

erp/urls.py;

from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='login'),
    url(r'^logout/$', 'django.contrib.auth.views.logout_then_login', {}, name='logout'),
    url(r'^search/', include('haystack.urls')),
    url(r'^inventory/', include('inventory.urls')),
)

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += patterns('',
    url(r'^__debug__/', include(debug_toolbar.urls)),
)

and inventory/urls.py:

from django.conf.urls import url, patterns
from .forms import CarrierWizardForm1, CarrierWizardForm2, MovementWizardForm1,MovementWizardForm2
from . import views

carrier_wizard_forms = [CarrierWizardForm1, CarrierWizardForm2]
movement_wizard_forms = [MovementWizardForm1, MovementWizardForm2]

urlpatterns = patterns('',
    url(r'^$', views.PartNumberListView.as_view(), name='inventory_list_index'),
    url(r'^parttype/$', views.part_type_list, name='index'),
    url(r'^parttype/(?P<parttype>\d{2})/$', views.part_type_view, name='part_type_view'),
    url(r'^partnumber/$', views.PartNumberListView.as_view(), name='partnumber_list'),
    url(r'^partnumber/add/$', views.PartNumberCreateView.as_view(), name='partnumber_add'),
    url(r'^partnumber/(?P<slug>[-\w]+)/$', views.PartNumberView.as_view(), name='partnumber_view'),
    url(r'^partnumber/(?P<slug>[-\w]+)/update/$', views.PartNumberUpdateView.as_view(), name='partnumber_update'),
    url(r'^partnumber/(?P<slug>[-\w]+)/delete/$', views.PartNumberDeleteView.as_view(), name='partnumber_delete'),
    ....
       )

and erp/settings/dev.py:

# Django settings for erp project.
# settings.py

from unipath import Path

PROJECT_DIR = Path(__file__).ancestor(3)
MEDIA_ROOT = PROJECT_DIR.child("media")
STATIC_ROOT = PROJECT_DIR.child("static")
STATICFILES_DIRS = (
  PROJECT_DIR.child("assets"),
)
TEMPLATE_DIRS = (
  PROJECT_DIR.child("templates"),
)


DEBUG = True
TEMPLATE_DEBUG = DEBUG

TIME_ZONE = 'Australia/Melbourne'
LANGUAGE_CODE = 'en-au'
SITE_ID = 1
USE_TZ = True

DATE_FORMAT = 'd/m/y'
SHORT_DATE_FORMAT = 'd/m/y'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'stronghold.middleware.LoginRequiredMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'erp.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'erp.wsgi.application'


INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.formtools',
    'django.contrib.humanize',
    'inventory',
    'django_extensions',
    'extra_views',
    'debug_toolbar',
    'django_tables2',
    'stronghold',
    'bootstrap3',
    'haystack',
)

LOGIN_URL = '/login'
LOGOUT_URL = '/logout'

# For Stronghold
STRONGHOLD_PUBLIC_NAMED_URLS = (
    'login',
    'logout',
)

# This is required by the debug toolbar middleware
INTERNAL_IPS = ('192.168.0.16','0.0.0.0','127.0.0.1','::1', '192.168.0.115')

# This is reqquired by django_tables2
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
                           "django.core.context_processors.debug",
                           "django.core.context_processors.i18n",
                           "django.core.context_processors.media",
                           "django.core.context_processors.static",
                           "django.core.context_processors.tz",
                           "django.contrib.messages.context_processors.messages",
                           "django.core.context_processors.request"
                          )
}

LOGIN_REDIRECT_URL = '/inventory/'

DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
]

def show_toolbar(request):
    return True  # Always show toolbar, for example purposes only.

DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
'INSERT_BEFORE': '</body>',
'ENABLE_STACKTRACES': True,
}

# This is required for Haystack - the search engine
HAYSTACK_CONNECTIONS = {
      'default': {
    'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
    'URL': 'http://127.0.0.1:8085/solr/erp',
  },
}

My wsgi is the standard with minor settings mod:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "erp.settings.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My apache2/sites-avail/erp.conf is:

<VirtualHost *:80>
   ServerName deverp
   ServerAdmin administrator
   DocumentRoot /path/www/dev/erp/erp/
   ErrorLog /var/log/apache2/dev/error.log
   CustomLog /var/log/apache2/dev/access.log combined
   WSGIDaemonProcess deverp python-path=/path/www/dev/erp/erp:/path/.virtualenvs/erp-dev/lib/python2.7/site-packages
   WSGIProcessGroup deverp
   WSGIScriptAlias / /path/www/dev/erp/erp/erp/wsgi.py
  <Directory /path/www/dev/erp/erp/erp>
  <Files wsgi.py>
    Order deny,allow
    Allow from all
  </Files>
  </Directory>
</VirtualHost>
解决方案

So, I actually ran into a similar problem. Coincidentally after you posted in the issues for django-stronghold. The issue is in fact due to a missing setting in django-debug-toolbar.

The setting you are missing is:

DEBUG_TOOLBAR_PATCH_SETTINGS = False 

It will work with runserver, but if you try to run it with honcho, or gunicorn, or anything else that uses the WSGI interface it blows up.

Hope this helps!

EDIT: as mentioned below by @japhyr, its useful to check out the explicit setup instructions: http://django-debug-toolbar.readthedocs.org/en/1.0/installation.html#explicit-setup

这篇关于不正确配置:包含的urlconf&lt; project&gt; .urls中没有任何模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:31