2014-11-06 71 views
1

我有一個包含一些應用項目帳戶網站管理Django的反向不是在視圖中找到,但URL工作

在哪裏登錄我之後重定向用戶的視圖Webadmin。 事情是我可以通過瀏覽器瀏覽網頁Webadmin!這意味着該鏈接正在工作。

但是,每當我嘗試重定向查看它給了我這個錯誤。這裏是回溯

Environment: 


Request Method: POST 
Request URL: http://localhost:8000/account/login/ 

Django Version: 1.7 
Python Version: 3.4.0 
Installed Applications: 
('django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'debug_toolbar.apps.DebugToolbarConfig', 
'bootstrap3', 
'easy_pjax', 
'website', 
'account', 
'webadmin') 
Installed Middleware: 
('debug_toolbar.middleware.DebugToolbarMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware') 


Traceback: 
File "/home/nihan/venv/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response 
    111.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 
File "/home/nihan/workspace/hubx/account/views.py" in sign_in 
    57.      return redirect(webadmin_home) 
File "/home/nihan/venv/venv/lib/python3.4/site-packages/django/shortcuts.py" in redirect 
    74.  return redirect_class(resolve_url(to, *args, **kwargs)) 
File "/home/nihan/venv/venv/lib/python3.4/site-packages/django/shortcuts.py" in resolve_url 
    158.   return urlresolvers.reverse(to, args=args, kwargs=kwargs) 
File "/home/nihan/venv/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in reverse 
    546.  return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) 
File "/home/nihan/venv/venv/lib/python3.4/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 
    463.        (lookup_view_s, args, kwargs, len(patterns), patterns)) 

Exception Type: NoReverseMatch at /account/login/ 
Exception Value: Reverse for 'webadmin.views.list_sites' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 

這裏是網站應用程序(根應用程序)從WebAdmin的

from django.conf.urls import patterns, include, url 
from django.contrib import admin 
from django.conf.urls.static import static 
from django.conf import settings 

urlpatterns = patterns(
'', 
url(r'^$', 'website.views.home', name='home'), 
url(r'^account/', include('account.urls', namespace='account')), 
url(r'^admin/', include('webadmin.urls', namespace='webadmin')), 
url(r'^admin-panel/', include(admin.site.urls)), 
) 
if settings.DEBUG: 
    import debug_toolbar 
    urlpatterns += patterns('', 
    url(r'^__debug__/', include(debug_toolbar.urls)), 
    ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

url.py代碼我urls.py代碼應用

from django.conf.urls import patterns, url 
urlpatterns = patterns('', 
    url(r'create/$', 'webadmin.views.create', name='create'), 
    url(r'list/$', 'webadmin.views.list_sites', name='list_sites'), 
) 

url.py代碼賬號 App

from django.conf.urls import patterns, url 


urlpatterns = patterns('', 
    url(r'^view/(?P<id>\d+)/$', 'account.views.view', name='profile'), 
    url(r'^login/$', 'account.views.sign_in', name='sign_in'), 
    url(r'^register/$', 'account.views.sign_up', name='sign_up'), 
    url(r'^logout/$', 'account.views.signout', name='logout'), 
    url(r'^edit/$', 'account.views.edit', name='edit'), 
    url(r'^activate/(?P<token>\d{4})/$', 'account.views.activate', name='activate'), 
) 

而且我重定向到list_sites這個小碼

from django.shortcuts import redirect 
from webadmin.views import list_create as webadmin_home 

def someview(request): 
    return redirect(webadmin_home) 

我思念的東西(從其他應用程序等作品的看法)?爲什麼會出現這種錯誤?如何解決它? 在此先感謝

回答

1

您不重定向到視圖方法,您重定向到一個URL。在你的urls.py中,你給這個URL一個名字,所以這就是你需要使用的。

return redirect('webadmin:create') 
+0

我從非命名模式轉移到名稱空間模式時遇到過這種情況。幸運的是,我的功能測試在導致問題之前就已經找到了。 – 2014-11-12 18:13:37

0

它有助於查看您在websiteApp/urls.py中引用的'account.urls'文件,但它聽起來像是它沒有找到「account/urls.py」文件本身,或者該文件中「登錄」視圖的URL配置不正確。

+0

賬戶url.py加入後。 – 2014-11-07 06:03:38

0

from django.core.urlresolvers import reverse_lazy 
 

 
return reverse_lazy("webadmin:list_create")

+3

歡迎來到Joris網站。你能提供一些你的代碼的解釋嗎? – 2014-11-06 21:50:13

相關問題