0

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'),
]

view

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})

I try to redirect but I get

NoReverseMatch at /check_login/
Reverse for 'edit_news' with arguments '()' and keyword arguments '{'url_name_param': 'dtsik'}' not found. 0 pattern(s) tried: []

I read to other posts here that i have to remove "$" from empty url, when I do these

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

no error thrown but also no redirect to 'edit_news' , stay in same page an adds '/check_login/' in address bar

ditsikts
  • 286
  • 1
  • 2
  • 9
  • 1
    Possible duplicate of [What is a NoReverseMatch error, and how do I fix it?](http://stackoverflow.com/questions/38390177/what-is-a-noreversematch-error-and-how-do-i-fix-it) – e4c5 Aug 05 '16 at 06:22
  • Also, Your param name doesn't have an `m` on it in the url – Sayse Aug 05 '16 at 06:29
  • @Sayse I fix 'm', still same error – ditsikts Aug 05 '16 at 07:29
  • Then see the duplicate, the error you're getting should also be slightly different now. – Sayse Aug 05 '16 at 07:32
  • Same error. If I visit directly "http://127.0.0.1:8000/dtsik/edit_news/" works fine so url pattern should be ok – ditsikts Aug 05 '16 at 08:18

1 Answers1

0

I did not put the namespace.

this

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

change to

return redirect('profs:edit_news', url_name_para = request.POST.get('username'))
ditsikts
  • 286
  • 1
  • 2
  • 9