python - Passing object from one view to another in django via HttpResponseRedirect -
i have "upload" view creates instance of model once form has been filled-in , considered valid:
... crossstitch.models import pattern def upload(request): if request.method == 'post': form = uploadfileform(request.post, request.files) if form.is_valid(): newpattern = pattern(imagefile = request.files['pattern'],filename = request.post['title']) return httpresponseredirect(reverse('configure', args=newpattern)) ^^ else: form = uploadfileform() ... as indicated py up-arrows, pass instance of model next view. configure view below:
def configure(request, pattern): ... both of views have urls this:
url(r'^upload/$','crossstitch.views.upload', name='upload'), url(r'^configure/$','crossstitch.views.configure', name='configure'), however, i'm getting error:
typeerror @ /crossstitch/upload/ _reverse_with_prefix() argument after * must sequence, not pattern request method: post request url: http://127.0.0.1:8000/crossstitch/upload/ django version: 1.4.5 exception type: typeerror exception value: _reverse_with_prefix() argument after * must sequence, not pattern exception location: /usr/lib/python2.7/dist-packages/django/core/urlresolvers.py in reverse, line 476 python executable: /usr/bin/python python version: 2.7.3 python path: ['/home/stacey/work/django/staceyanne', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/pil', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7'] server time: wed, 4 sep 2013 15:22:12 +0200 how pass instance of object 1 view correctly?
the args keyword argument reverse is iterative. should pass e.g. list or tuple instead.
in case, however, pattern argument configure shouldn't object. in url configuration regex should contain identifier of pattern want configure, described in part 3 of tutorial. way in configure you'd fetch pattern id, , reverse call this: reverse('configure', args=[newpattern.id]).
Comments
Post a Comment