I will call cookies before all web page. For this reason, I should create value key before all of the page or module is called. Before any of the page is called, cookie should be constructed first, for my case. How can I manage this? Where should I put request.session['id']=Null
so that it will called first before any other page is called?
Asked
Active
Viewed 57 times
0

mavzey
- 379
- 1
- 5
- 13
2 Answers
1
You need to write a custom decorator to handle the situation.
You can read more about Decorators here: https://docs.djangoproject.com/en/dev/topics/http/decorators/
For example the csrf_exempt
decorator allows a request to be processed without the csrf token facility in forms, very useful for JSON based requests.
@csrf_exempt
def new(request):
if request.method == 'POST':
json_data = simplejson.loads(request.raw_post_data)
try:
Similarly have a custom decorator for ensuring cooking and use it as:
@ensure_cookie
def new(request):
...
Writing custom decorators: How to write a custom decorator in django?

Community
- 1
- 1

redDragonzz
- 1,543
- 2
- 15
- 33
0
You can put this code in process_request or process_view method in custom middleware.

kobuz
- 221
- 1
- 6