Our site has a main entity - city. Firstly a user selects a city from dropDownList (site stores it in session) and then uses the site's apps through /CITY/APP_NAME, for ex. www.mysite.com**/kyiv/**petitions/add.
I want to catch a city slug from an url and store it to a session. To do this, I have url.py like below:
url(r'(?P<townslug>[a-z]+)/',include(urls_modules)),
and url_modules.py
urlpatterns = [
url(r'^$', views.index, name="index"),
url(r'^edata/', include('edata.urls', namespace="edata")),
url(r'^crowdfunding/', include('crowdfunding.urls')),
url(r'^petitions/', include('petitions.urls', namespace="petitions")),
url(r'^budget/', views.budget, name="budget"),
url(r'^partners', views.partners),
]
My question is - how to cache city slug and put it into session directly from url_modules.py like:
request.session["town"] = Town.objects.get(slug=townslug).id
request.session["town_name"]= Town.objects.get(slug=townslug).name