I am developing a site based on cities and would like to pass in the city as a parameter via the url for the object creation page. What is the best way to go about this, I have been looking through the docs but can't seem to find this issue.
1 Answer
If I understand you correctly you want to do this
How to pass a variable from the url to a view in django?
In my case the variable I passed through I just added the the regex of the url in the urls.py Hope it helps.
Here is another link which is from the django docs which could help you understand urls and how to pass variables.
2 Comments
thesteve
I figured out how to successfully pass the variable into a list view to filter the queryset but am having trouble finding a way to use a passed in variable to automatically populate a model creation form. In other words I want to be able to have an "Add Restaurant Form" that automatically recognizes the city from the urlpattern such as '^/(?P<city>[-\w]+)/restuarant/add/$'
darren
when you go to the Add Restaurant Form you and specifying a URL right? Just pass the the id or city code along with that url?