1

when user click make thumbnailbutton ,it will call def thumbin the view and then render to http://127.0.0.1:8000/upload/thumb

I want to change to redirect to the url with the id number in database(Item.objects.all()) like : http://127.0.0.1:8000/upload/thumb/123

But not get it. Please help me.Thank you very much.

My code:

urls.py

urlpatterns = patterns('', 
    url(r'^$', views.background, name='background'),
    url(r'^thumb/(?P<result>\d+)$', views.thumb, name='thumb'),

views.py

def thumb(request,result):
    if request.method=="POST":
        photoid = request.POST['photoid']
        photowidth = request.POST['photowidth']
        item=Item.objects.filter(id=photoid) 
        return redirect(reverse('imageupload:thumb',kwargs={'result':photoid,'item':item }))

return HttpResponseRedirect(reverse('imageupload:background'))

templates:

  <form action="{% url 'imageupload:thumb'  i.id %}" method="POST" id="create_post">
2
  • Perhaps you mean to use kwargs={'item' : item} instead of args. Note, however, that if you're using named parameters in your url definition then your kwarg name will need to match. aka: kwargs={'result' : item} Commented Dec 9, 2014 at 3:08
  • I think in general, however, you might be a bit confused since the code doesn't seem to make a lot of sense and there are several problems. Rather than posting a bunch of code can you specify what it is you're trying to do? Commented Dec 9, 2014 at 3:10

1 Answer 1

4

When you use named parameter, you need to do like this:

return redirect(reverse('imageupload:thumb',kwargs={'result':item}))

And in your forms.py, you also need to modify your action to this:

action="{% url 'imageupload:thumb' result %}"

You can also access result in views.py like this:

def thumb(request, result):
    print result
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.