Hi everyone,
I digged more but i'm still stuck.
I understood that i have to use namespaceURL.
So i modified my url.py this way :
from myAppFront.views import article
url (r'^article/(?P<id>\d+)/$',
myAppFront.views.article,
name='article'),
and this is my addComment view :
def addComment(request, id):
article = article.objects.get(id=id)
if request.method == 'POST':
form = CommentForms(data=request.POST)
if form.is_valid():
cf_comment = form.cleaned_data['cf_comment']
cf_writer = request.user
cf_date = datetime.datetime.now()
cf_video = video
c1 = Commentaire.objects.create(comment=cf_comment,
dateComment=cf_date, writer=cf_writer, article=cf_article)
c1.save()
#return HttpResponseRedirect(reverse('myAppFront.views.article',
args=(id,)))
return HttpResponseRedirect(reverse('myAppFront.views.article',
kwargs={'id': id}))
It's still doesn't work, i have this error :
NoReverseMatch at /article/1/addComment/
Reverse for 'myAppFront.views.article' with arguments '()' and keyword
arguments '{'id': u'1'}' not found.
I don't know if it can help but this is my article view :
def article(request, id):
article = article.objects.get(id=id)
commentaires = Commentaire.objects.filter(article=article.id
).order_by("-dateComment")
date = datetime.datetime.now()
c = Context({
'article' : article,
'commentaires' : commentaires,
'now' : date,
})
form = CommentForms()
c['form'] = form
return render_to_response('myAppFront/article.html', c,
context_instance=RequestContext(request))
thx for your help :)
On Sun, Oct 23, 2011 at 5:01 PM, nicolas HERSOG <[email protected]> wrote:
> Hi everyone,
>
> I'm stuck with the redirection in django.
>
> This is my url.py
>
> (r'^article/(?P<id>\d+)/$', 'myapp.myappFront.views.article'),
> (r'^article/(?P<id>\d+)/addComment/$',
> 'myapp.myappFront.views.addComment'),
>
> I developed a little view in order to add comment to my article, this is my
> view.py
>
> def article(request, id):
> article = article.objects.get(id=id)
> commentaires = Commentaire.objects.filter(article=article.id
> ).order_by("-dateComment")
> #dateTime
> date = datetime.datetime.now()
>
> c = Context({
> 'article' : video,
> 'commentaires' : commentaires,
> 'now' : date,
> })
> form = CommentForms()
> c['form'] = form
> return render_to_response('myappFront/article.html', c,
> context_instance=RequestContext(request))
> def addComment(request, id):
> article = article.objects.get(id=id)
> if request.method == 'POST':
> form = CommentForms(data=request.POST)
> if form.is_valid():
> cf_comment = form.cleaned_data['cf_comment']
> cf_writer = request.user
> cf_date = datetime.datetime.now()
> cf_video = video
> c1 = Commentaire.objects.create(comment=cf_comment,
> dateComment=cf_date, writer=cf_writer, video=cf_video)
> c1.save()
> else:
> c = Context({
> 'id' : id,
> })
> #return render_to_response('myappFront/article.html', c,
> context_instance=RequestContext(request))
> #return HttpResponseRedirect(reverse('myappFront.views.article',
> args=(id,)))
> #return HttpResponseRedirect(reverse('myappFront.views.article',
> kwargs={'id': id}))
> return HttpResponseRedirect(reverse('myappFront.views.article',
> args=(id,)))
>
> The view article works well, my form for add comment seems ok, i can add
> comment to my article, but the problem is
> the redirection at the end of the addComment method.
> As u see, I tried many many syntax in order to redirect the user to the
> article, but all of this test failed.
> Every time i have this kind of error :
>
> NoReverseMatch at /article/9/addComment/
> Reverse for 'myAppFront.views.article' with arguments '(u'9',)' and keyword
> arguments '{}' not found.
>
> Any idea ?
>
> Thx for all :)
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.