Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django url parameter passing

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:

  1. Enter username and password in url with parameters for date and id and be able to view rooms available based on what is entered
  2. Enter username, password and dates and room code to be able to book the room

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.

like image 951
user1270384 Avatar asked Feb 21 '14 00:02

user1270384


People also ask

How do I pass multiple parameters in URL?

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 "&".

How do I get all query parameters in Django?

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.


1 Answers

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
like image 57
schillingt Avatar answered Oct 07 '22 18:10

schillingt