带有名称网址的Django Reverse

时间:2018-12-03 14:28:29

标签: django

我觉得这是我不应该遇到的麻烦,但是我很沮丧。我尝试使用Google,但是我看到的每个帖子在模板中都有问题。

我在urls.py中有以下内容:

path('AddStudent/thanks', views.thanks, name='AddStudentThanks')

我有一个要链接到另一个视图的FBV。我可以用

return HttpResponseRedirect("AddStudent/thanks")

但是当我尝试将其过时并使用带有以下代码的命名url

return HttpResponseRedirect(reverse("AddStudentThanks")) #go 

我收到以下错误和回溯

NoReverseMatch at /advising/AddStudent
Reverse for 'AddStudentThanks' not found. 'AddStudentThanks' is not a valid view function or pattern name.
Request Method: POST
Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/advising/AddStudent

Django Version: 2.1.2
Python Version: 3.6.6
Installed Applications:
['advising.apps.AdvisingConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/ne573414/env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/ne573414/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/home/ne573414/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/ne573414/Desktop/School/SD/proj/tnb/tnb/ETM_Advising/advising/views.py" in AddStudent
  48.           return HttpResponseRedirect(reverse("AddStudentThanks")) #go 

File "/home/ne573414/env/lib/python3.6/site-packages/django/urls/base.py" in reverse
  90.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))

File "/home/ne573414/env/lib/python3.6/site-packages/django/urls/resolvers.py" in _reverse_with_prefix
  622.         raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /advising/AddStudent
Exception Value: Reverse for 'AddStudentThanks' not found. 'AddStudentThanks' is not a valid view function or pattern name.

我想念什么?

0 个答案:

没有答案