root urls
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('profs.urls')),
]
app urls
app_name = 'profs'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^contact/', views.contact, name='contact'),
url(r'^check_login/', views.check_login, name='check_login'),
url(r'^(?P<url_name_para>[a-zA-Z]+)/$', views.show, name='show'),
url(r'^(?P<url_name_para>[a-zA-Z]+)/edit_news/$', views.edit_news, name='edit_news'),
]
视图
def check_login(request):
if request.method == 'POST':
if request.POST.get('username') != '' and request.POST.get('password') != '' and request.POST.get('password') != 'free':
prof = get_object_or_404(Professional, url_name=request.POST.get('username'))
if prof.subscription == request.POST.get('password'):
return redirect('edit_news', url_name_para = request.POST.get('username'))
#return render(request, 'profs/edit_news.html', {'prof': prof})
else:
return render(request, 'profs/test.html', {'val': 1})
else:
return render(request, 'profs/test.html', {'val': 2})
else:
return render(request, 'profs/test.html', {'val': 3})
我尝试重定向但是我得到了
NoReverseMatch at /check_login/
Reverse for 'edit_news' with arguments '()' and keyword arguments '{'url_name_param': 'dtsik'}' not found. 0 pattern(s) tried: []
我在这里阅读其他帖子,我必须删除&#34; $&#34;来自空网址,当我这样做时
url(r'^', views.index, name='index'),
没有抛出任何错误,也没有重定向到&#39; edit_news&#39; ,留在同一页面添加&#39; / check_login /&#39;在地址栏
答案 0 :(得分:0)
我没有放置命名空间。
此
{{1}}
更改为
{{1}}