I am not even sure what category in Django this question falls in and I am very new to django. I have tried looking for Django post requests, parameter passing and even checked under Django APIs but have not found what I am looking for. What I am trying to do is create an API for my client but it must be done in Django. If I was to do this in .Net I could use http post and http get and web services but I am not at all sure how this is done in Django. What my client wants to do is to be able to see:
No interface needed just simple parameter passing through url. Is this possible with Django and if yes can somebody please point me in the right direction.
Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
We can access the query params from the request in Django from the GET attribute of the request. To get the first or only value in a parameter simply use the get() method. To get the list of all values in a parameter use getlist() method.
What you're looking for are captured parameters
Below is a code snippet from the above link.
# urls.py
from django.conf.urls import patterns, url
urlpatterns = patterns('blog.views',
url(r'^blog/(?P<year>\d{4})/$', 'year_archive', {'foo': 'bar'}),
)
# views.py
def year_archive(request, year, foo=None):
# view method definition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With