Answer the question
In order to leave comments, you need to log in
How to describe GET parameter with regex pom in urls.py Django?
There is the following url: http://mydomain.ru/?param1=value1¶m2=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),
]
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))
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question