Naresh
Naresh

Reputation: 1972

How to read parameters from request in django

I need to read some parameters being passed in and perform some action in django. How can I do that.

url = 172.15.20.116/request

and server is requesting with below parameters

url = 172.15.20.116/request/1289/

here 1289 is parameter. How to parse it?

Upvotes: 0

Views: 40

Answers (1)

Matt Seymour
Matt Seymour

Reputation: 9415

To so this you need to capture this in the urls.

You will need to look into the django url dispatcher this page has pretty much everything you need to get started. Take your time, learn and then implement.

Maybe something like:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^request/(?P<id>\d+)/$', 'appname.views.my_request_view'),
]

views.py

def my_request_view(request, id):
    ... # logic goes here

Upvotes: 1

Related Questions