2016-08-05 2 views
0

корень URLsNoReverseMatch Джанго

urlpatterns = [ 
    url(r'^admin/', admin.site.urls), 
    url(r'^', include('profs.urls')), 
] 

приложение 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: [] 

Я читал другие посты здесь, что я должен удалить «$» из пустого URL, когда я делаю эти

url(r'^', views.index, name='index'), 

не брошенную никакой ошибки, но и не перенаправлять на «edit_news», оставаться в той же странице ап добавляет «/ check_login/'в адресной строке

+1

Возможный дубликат [Что такое ошибка NoReverseMatch, и как это исправить?] (Http://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – e4c5

+0

Кроме того, ваше имя параметра не содержит 'm' на нем в URL-адресе – Sayse

+0

@Sayse I fix 'm' , по-прежнему такая же ошибка – ditsikts

ответ

0

Я не помещал пространство имен.

это

return redirect('edit_news', url_name_para = request.POST.get('username')) 

изменение

return redirect('profs:edit_news', url_name_para = request.POST.get('username')) 
Смежные вопросы