Django url parameter passing

user1270384 picture user1270384 · Feb 21, 2014 · Viewed 11.5k times · Source

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.

Answer

schillingt picture schillingt · Feb 21, 2014

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