开发者

Handling url reverse function for django view with multiple kwargs

开发者 https://www.devze.com 2023-03-30 09:38 出处:网络
I\'m building a database application using django. Much of the data recorded requires supporting documentation (this documentation is scanned in and uploaded). Many of my django views include links to

I'm building a database application using django. Much of the data recorded requires supporting documentation (this documentation is scanned in and uploaded). Many of my django views include links to my scanning view, and arguments are passed into that view. In fact the view that handles the scanning takes 9 optional kwargs. I can't work out how to set up my urls.py so as to handle the following:

HttpResponseRedirect(reverse('general_doc_upload', kwargs = doc_parameters))

I'm sure there must be a nicer way of handling this than trying to write Regex for every possible combination of kwargs.

Unfortunately the I don't have a lot of leeway开发者_StackOverflow with the underlying database structure, this has been specified by the client, the django models (and corresponding views) have been written to fit this structure.


This sort of thing is where putting the parameters in the URL breaks down. Instead, you should pass them as GET parameters - /my/url/upload/?param1=foo&param2=bar etc.

In your urlconf, just match the basic pattern with r'upload/$', and get the parameters in your view with request.GET['param1'] etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消