I have a project containing some Apps like Account , Webadmin , etc
Where after login i am redirecting a user to a view of Webadmin. Thing is i can view that page of Webadmin via Browser or so! That means the link is working.
But whenever i try to redirect to view it gives me this error. Here is the traceback
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: []
Here is my urls.py code from Website App ( Root app )
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 code from webadmin App
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 code from account 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'),
)
And i redirect to list_sites with this little code ( Works with other views from other apps )
from django.shortcuts import redirect
from webadmin.views import list_sites as webadmin_home
def someview(request):
return redirect(webadmin_home)
Am i missing something? Why is that error orchering? How to fix it? Thanks in advance
You don't redirect to a view method, you redirect to a URL. In your urls.py, you've given that URL a name, so that's what you need to use.
return redirect('webadmin:create')