40đź‘Ť
Don’t. You shouldn’t match query string with URL Dispatcher.
You can access all values using request.GET
dictionary.
urls
(r'^pbanalytics/log/$', 'mydjangoapp.myFunction')
function
def myFunction(request)
param1 = request.GET.get('param1')
3đź‘Ť
Django’s URL patterns only match the path component of a URL. You’re trying to match on the querystring as well, this is why you’re having trouble. Your first regex does what you wanted, except that you should only ever be matching the path component.
In your view you can access the querystring via request.GET
- [Django]-Difference between User.objects.create_user() vs User.objects.create() vs User().save() in django
- [Django]-Serializer call is showing an TypeError: Object of type 'ListSerializer' is not JSON serializable?
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
2đź‘Ť
The ?
character is a reserved symbol in regex, yes. Your first attempt looks like proper escaping of it.
However, ?
in a URL is also the end of the path and the beginning of the query part (like this: protocol://host/path/?query#hash
.
Django’s URL dispatcher doesn’t let you dispatch URLs based on the query part, AFAIK.
My suggestion would be writing a django view that does the dispatching based on the request.GET
parameter to your view function.
- [Django]-How to produce a 303 Http Response in Django?
- [Django]-Django – No module named _sqlite3
- [Django]-Django.db.utils.ProgrammingError: relation "bot_trade" does not exist
1đź‘Ť
The way to do what the original question was i.e. catch-all in URL dispatch var…
url(r'^mens/(?P<pl_slug>.+)/$', 'main.views.mens',),
or
url(r'^mens/(?P<pl_slug>\?+)/$', 'main.views.mens',),
As far as why this is needed, GET URL’s don’t exactly provide good “permalinks” or good presentation in general for customers and to clients.
Clients often times request the url be formatted i.e.
www.example-clothing-site.com/mens/tops/shirts/t-shirts/Big_Brown_Shirt3XL
this is a far more readable interface for the end-user and provides a better overall presentation for the client.
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-Name '_' is not defined
- [Django]-Sending post data from angularjs to django as JSON and not as raw content