我是 Django 的新手,正在尝试设置一个简单的联系表单,该表单在成功提交时重定向到感谢页面。我在提交后无法重定向到感谢页面并收到以下错误:NoReverseMatch at /contact/Reverse for 'thanks' not found. 'thanks' is not a valid view function or pattern name.这是我的 urls.pyapp_name = 'home'urlpatterns = [ url(r'^$', views.HomePageView.as_view()), url(r'^contact/$', views.ContactView, name='contact'), url(r'^thanks/$', views.ThanksView, name='thanks'),]和我的 views.pydef ContactView(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['subject'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] try: send_mail(subject, message, from_email, ['admin@example.com']) except BadHeaderError: return HttpResponse('Invalid header found.') return redirect('thanks') return render(request, 'contact.html', {'form': form})def ThanksView(request): return render(request, 'thanks.html', {})我在我的 settings.pyTEMPLATES = [ { 'DIRS': [ os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, '/home', 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', # Third Party Apps 'social_django.context_processors.backends', # <-- 'social_django.context_processors.login_redirect', # <-- ], }, },]有人可以指出我在哪里犯了错误吗?
3 回答
添加回答
举报
0/150
提交
取消