redirect NoReverseMatch Django error

192 views
Skip to first unread message

Dimitris Tsiktsiris

unread,
Aug 5, 2016, 7:00:21 AM8/5/16
to Django users
Here are my view and urls
app url
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]+)/edit_news/$', views.edit_news, name='edit_news'),
    url
(r'^(?P<url_name_para>[a-zA-Z]+)/$', views.show, name='show'),
]
root url
urlpatterns = [
    url
(r'^admin/', admin.site.urls),
    url
(r'^', include('profs.urls')),
]
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})
def edit_news(request, url_name_para):
    if request.method == 'POST':
        Professional.objects.filter(url_name=request.POST.get('url_name')).update(update_news=request.POST.get('editor1'))
        return render(request, 'profs/index.html')

    prof = get_object_or_404(Professional, url_name=url_name_para)
    return render(request, 'profs/edit_news.html', {'prof': prof})

If I visit directly "http://127.0.0.1:8000/dtsik/edit_news/" I get this error
NoReverseMatch at /dtsik/edit_news/
Reverse for 'edit_news' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['(?P<url_name_para>[a-zA-Z]+)/edit_news/$']


When I submit to check login I get this error
NoReverseMatch at /check_login/
Reverse for 'edit_news' with arguments '()' and keyword arguments '{'url_name_para': 'dtsik'}' not found. 0 pattern(s) tried: []

What is the problem? Though is something with url pattern but cant figure it out

ludovic coues

unread,
Aug 5, 2016, 7:05:18 AM8/5/16
to django...@googlegroups.com
Have you added your app to the INSTALLED_APPS setting ?
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/061336d6-7ff2-4cc1-bad5-907fe3b5a988%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Sergiy Khohlov

unread,
Aug 5, 2016, 12:45:46 PM8/5/16
to django-users

Also please add your templates. Looks like you are using URLs in the templates


5 серп. 2016 14:05 "ludovic coues" <cou...@gmail.com> пише:

> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/061336d6-7ff2-4cc1-bad5-907fe3b5a988%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages