0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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/$'
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?

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.