我有一个django(1.6.x)项目,与dev服务器运行良好,但在Ubuntu 12.04.3上的Apache2(2.2.22.1)和mod_wsgi(3.3-4)下出现错误,出现错误
错误configuration:包含的URLconf erp.urls中没有任何模式
我不明白为什么它可以与开发服务器,但不是Apache2 / mod_wsgi,我发现很难追查错误来自哪里。
还有一些类似的SO问题,但我唯一使用的地方(先前发现的一个问题)是在我的模型中的get_absolute_url – 这应该没问题?
为什么Apache HTTP服务器在任务pipe理器上显示2个进程?
禁用特殊目录下的一些PHPfunction
Apache SetEnv无法像mod_wsgi一样按预期工作
Apacheconfiguration – 多个python版本
该项目build立了一个两勺的风格,特别是布局是:
<repository_root>/<django_project_root>/<configuration_root>/
这意味着:
erp_root/erp/erp/
和设置是
erp_root/erp/erp/settings/*py (包括__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/$',{'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)),)
和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('',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/$',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 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',},}
我的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 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>
如何在.htaccessredirect后通过ajax请求保留POST数据?
如何用Apache mod_rewrite隐藏.html扩展名
当ajax使用apache mod_proxy和不同的域调用nodejs时会话
使用Apache POI和Spring框架将Excelfile upload到数据库
.htaccess在根目录下的mod_rewrite,但需要它跳过所有其他目录
所以我遇到了类似的问题 巧合的是,你在django -holdhold的问题上发布之后。 这个问题实际上是由于django-debug-toolbar中缺少设置。
您缺少的设置是:
DEBUG_TOOLBAR_PATCH_SETTINGS = False
它将与runserver一起工作,但是如果你尝试用honcho或者gunicorn或者其他使用Wsgi接口的东西来运行它,它就会崩溃。
希望这可以帮助!
编辑:如下所述@japhyr,它有用的检查显式设置说明: http ://django-debug-toolbar.readthedocs.org/en/1.0/installation.html#explicit-setup
我使用reverse而不是reverse_lazy来定义RedirectView的url参数。
class YourRedirectView(RedirectView): url = reverse('reversed_url')
由于urls.py尚未初始化,错误即将到来。 只要使用:
class YourRedirectView(RedirectView): url = reverse_lazy('reversed_url')
从django 1.5升级到1.6后,我遇到了类似的问题。 我不确定我的经验是否与你的一样。
首先,你可以滚动错误,并检查admin.autodiscover()是什么产生的问题? 或者注释掉这一行,看看是否会加载一个页面。
我有一个非常类似的问题。 我的项目在测试服务器上工作正常,但是当我尝试部署到gunicorn时,我得到相同的错误配置错误。
如果我注释掉包含另一个url文件(即url(r'^admin/',的url url(r'^admin/',那么我的其他url就可以正常工作。
[更新]我能够进一步缩小到只有我包括的url文件之一,但找不到任何特别的。 但是,在我的settings.py文件中设置Debug=False似乎已经解决了我的问题。
另外,请确保在包含的文件中包含urlpatterns ,并且拼写正确
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。