I
I
Ilya Oskin2016-11-19 13:04:33
Django
Ilya Oskin, 2016-11-19 13:04:33

How to describe GET parameter with regex pom in urls.py Django?

There is the following url:
http://mydomain.ru/?param1=value1&param2=value2
How to describe such a URL in the Django url-config (urls.py), so that these get parameters can then be used in the view?
urls.py

from django.conf.urls import patterns,  url
from . import views
from teaguru_lp import views

urlpatterns = [
    url(r'^$', views.page),
]

views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Product, Page

def page(request, param1, param2):
    prods = Product.objects.all()
    template = loader.get_template('base_gen.html')
    context = {
        'prods' : prods,
    }
    return HttpResponse(template.render(context, request))

The network is full of examples on parsing get parameters, but they are all for PHP

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2016-11-19
@SorexCA

GET parameters don't go to path, they don't need to be put into regexps.
In the view, they are available via request.GET

S
sim3x, 2016-11-19
@sim3x

https://www.google.com.ua/search?q=django+http+get...
stackoverflow.com/questions/150505/capturing-url-p...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question