我有一個在生產服務器上運行的Django應用程序。它在nginx後面用gunicorn 0.14.2處理。當我重新加載應用程序(通過重新加載gunicorn工人),我得到這個錯誤:爲什麼Django在加載我的URLconf時發出警告?
Traceback (most recent call last):
File "/opt/nybooks/venv/myapp/lib/python2.6/site-packages/django/core/handlers/base.py", line 101, in get_response
request.path_info)
File "/opt/nybooks/venv/myapp/lib/python2.6/site-packages/django/core/urlresolvers.py", line 250, in resolve
for pattern in self.url_patterns:
File "/opt/nybooks/venv/myapp/lib/python2.6/site-packages/django/core/urlresolvers.py", line 283, in _get_url_patterns
raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
ImproperlyConfigured: The included urlconf myapp.urls doesn't have any patterns in it
其他同這一問題已經普遍注意到,雖然在URL配置使用reverse
發生了,但我沒有在任何使用reverse
URLconfs(也不用於任何第三方應用程序)。此外,這個錯誤只有發生在生產中 - 從未在開發中(使用Django dev服務器)或在我的分段服務器上(使用nginx後面的gunicorn 0.14.2)。在重新加載期間,它在任何其他時間似乎也不會造成該網站的麻煩。
任何想法是什麼原因造成的問題?
下面是主要的URLconf(和一個堆棧跟蹤參考):
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
from django.http import HttpResponse, Http404
from django.views.generic.simple import direct_to_template, redirect_to
from myapp.apps.magazine.views import *
from myapp.apps.books.views import *
from myapp.apps.forms.views import *
from myapp.apps.blogext.views import *
from myapp.apps.sharing.views import expand_url, email_link_send
from myapp.apps.magazine.feeds import *
from satchmo_utils import urlhelper
from satchmo_store.urls import urlpatterns
from myapp.apps.myapp_shop.views import *
admin.autodiscover()
if settings.SHOP_BASE == '':
shopregex = '^'
else:
shopregex = '^' + settings.SHOP_BASE[1:] + '/'
myapp_patterns = patterns('',
# calendar
(r'^calendar/', include('events.urls')),
# for multimedia SWF access
#(r'^crossdomain.xml$', direct_to_template, {'template': 'crossdomain.xml'}),
# intercept checkout
# TODO: need to use a config value
(r'^catalog/checkout/$', 'myapp.apps.cart.views.myapp_checkout', {'SSL': not settings.LOCAL_DEV}, 'myapp_checkout'),
(r'^catalog/add/$', 'myapp.apps.cart.views.smart_add_wrapper', {}, 'myapp_smart_add'),
# URLs for NYRB apps
(r'^$', direct_to_template, {'template': 'newhomepage.html'}),
(r'^newhomepage/$', direct_to_template, {'template': 'newhomepage.html'}),
(r'^mobile/$', redirect_to, {'url': '/', 'permanent': True}),
(r'^books/authors/', include('myapp.apps.books.urls.authors')),
(r'^books/', include('myapp.apps.books.urls.books')),
(r'^articles/', include('myapp.apps.magazine.urls.articles')),
(
r'^mobile/articles/archives/(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
redirect_to,
{'url': '/articles/archives/%(year)s/%(month)s/%(day)s/%(slug)s/', 'permanent': True},
),
# for national poetry month (april)
url(
regex = r'^national-poetry-month/',
view = poetry_month,
name = 'poetry_month',
),
(r'^issues/', include('myapp.apps.magazine.urls.issues')),
(r'^contributors/', include('myapp.apps.magazine.urls.contributors')),
(r'^galleries/', include('myapp.apps.magazine.urls.illustrations')),
(r'^multimedia/', include('myapp.apps.multimedia.urls.multimedia')),
(r'^online/$', direct_to_template, {'template': 'online.html'}),
#(r'^search/', include('myapp.apps.search.urls')),
(r'^search/', include('solango.urls')),
(r'^textareas/', include('myapp.apps.textareas.urls')),
(r'', include('myapp.apps.forms.urls')),
(r'^utils/', include('myapp.apps.utils.urls')),
#(r'^rss/$', 'myapp.apps.magazine.views.rss_list'),
(r'^rss/huffpo/$', redirect_to, {'url': '/articles/feeds/huffpo/', 'permanent': False}),
(r'^rss/googlenews/$', redirect_to, {'url': '/articles/feeds/googlenews/', 'permanent': False}),
(r'^newsletter/', include('myapp.apps.newsletter.urls')),
(r'^subscriptions/', include('myapp.apps.newsubscriptions.urls')),
(r'^shared/', include('myapp.apps.sharing.urls')),
(r'^counter/', include('myapp.apps.counter.urls')),
# Redirects for legacy NYRB system
(r'^nyrev/(\w+)', uber_legacy_article_redirect),
(r'^nyrev/', redirect_to, {'url': '/'}),
(r'contents/(?P<legacy_date>\d+)/', legacy_issue_detail_redirect),
(r'^archives/browse/?$', legacy_browse_archives),
(r'^gallery/gallery-browse/?$', legacy_gallery_browse),
(r'^gallery/', legacy_illustration),
(r'authors/(?P<legacy_author_id>\d+)/', legacy_author_detail_redirect),
#(r'shop/product', legacy_book_detail_redirect),
(r'^shop/product/?$', legacy_product),
(r'^myapp/browse/?$', legacy_book_browse),
(r'blogs/myapplog/post/(\d+)/(?P<slug>[-\w]+)/$', solango_blogsearch_redirect),
# URL shortening
(r'^u/(?P<short_url>[a-zA-Z0-9]+)/$', expand_url),
# NYRB shop
(r'^shop/', include('myapp.apps.myapp_shop.urls')),
(r'^admin/shop/order/csv/?', csv_order_export_day),
(r'^admin/shop/order/(?P<order_id>\d+)/csv/?', csv_order_export),
# URLs for Savoy apps
(r'^tags/', include('savoy.contrib.sections.tag_urls')),
(r'^podcasts/', include('savoy.contrib.podcasts.urls')),
(r'^blogs/$', redirect_to, {'url': "/blogs/myapplog/", 'permanent': False}),
(r'^blogs/', include('savoy.contrib.blogs.urls')),
(r'^media/', include('savoy.core.media.urls')),
# this is to use our own edit profile view
(r'^users/(?P<username>.+)/edit/$', edit_profile),
(r'^users/', include('savoy.core.profiles.urls')),
# django-authopenid
(r'^account/getusername/', get_lost_username),
#(r'account/signin/?', 'myapp.apps.forms.views.dual_login'),
(r'account/signin/?', 'django.contrib.auth.views.login', {'template_name': 'authopenid/signin.html'}),
(r'account/signout/?', 'django.contrib.auth.views.logout', {'next_page': '/'}),
(r'account/sendpw/?', 'myapp.apps.forms.views.dual_sendpw'),
(r'account/resetpw/?', 'myapp.apps.forms.views.reset_pw'),
(r'account/signup/?', 'myapp.apps.forms.views.link_and_signup'),
#(r'^account/', include('django_authopenid.urls')),
# django-mailfriend
(r'^mail_friend/send/?', email_link_send),
(r'^mail_friend/', include('mailfriend.urls')),
# django.contrib.comments
# Django admin (Satchmo additions):
(r'^admin/print/(?P<doc>[-\w]+)/(?P<id>\d+)', 'shipping.views.displayDoc'),
(r'^admin/product/configurableproduct/(?P<id>\d+)/getoptions/', 'product.views.get_configurable_product_options'),
# Orders
(r'^admin/open-orders/$', 'myapp.apps.myapp_shop.views.open_orders'),
# Institutional subscription CSV
(r'^admin/subscriptions/institutionalsubscription\.csv', 'myapp.apps.subscriptions.views.institutional_sub_csv'),
# COUNTER admin for institutional reports
#(r'^admin/institution-counts/multiple-report/csv/$', 'myapp.apps.subscriptions.views.institution_multiple_csv'),
#(r'^admin/institution-counts/multiple-report/$', 'myapp.apps.subscriptions.views.institution_multiple_report'),
(r'^admin/institution-counts/institutions/(?P<id>\d+)/csv/', redirect_to, {'url': '/counter/%(id)s.csv'}),
(r'^admin/institution-counts/institutions/(?P<id>\d+)/$', redirect_to, {'url': '/counter/%(id)s/'}),
#(r'^admin/institution-counts/process_file/?$', 'myapp.apps.subscriptions.views.institution_process_file'),
(r'^admin/institution-counts/$', redirect_to, {'url': '/counter/'}),
# Django admin (standard)
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
# custom feeds
(r'^feed/author/(?P<slug>[-\w]+)/$', AuthorFeed()),
)
# attach satchmo patterns after our patterns so we can override if needed
from satchmo_store.urls import urlpatterns
urlpatterns = myapp_patterns + urlpatterns
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
(r'media/(?P<path>.*)', 'serve', {'document_root': settings.MEDIA_ROOT}),
)
向我們展示您的urlconf的消毒版本。 – agf 2012-04-12 21:33:51
您對登臺和生產服務器有不同的local_settings.py文件嗎?兩者有什麼區別?我認爲反向也可以在視圖中調用。如果是這樣,對於視圖導入來說,一個分而治之的方法可能會發現問題。如果使用不同的虛擬環境,在每個環境中運行pip凍結可能會顯示一些庫差異。 – mtnpaul 2012-06-10 20:07:50
您是否嘗試以某種方式調試此url配置?也許你可以在它裏面放一些打印文件(在不同的行中......例如:print myapp_patterns和print urlpatterns)然後,打開一個python shell並執行:from the_app_you_want import urls,你會看到怎麼回事與您的網址模式 – marianobianchi 2012-06-12 02:59:55