I\'m building a student management system using Django.
In this code, The user search for a student with the encrypted query
name=StudentName&grade=Grade&
To access the token
and student_id
variables in profile_view
, you can use request.session.
In your process_view
, set token
and student_id
in the session.
def process_view(..):
...
request.session['token'] = token # set 'token' in the session
request.session['student_id'] = student_id # set 'student_id' in the session
..
Then in your profile_view
, you can access these 2 variables from the session. You don't need to pass those 2 variables in the URL then.
def profile_view(..):
...
token = request.session['token'] # get 'token' from the session
student_id = request.session['student_id'] # get 'student_id' from the session
..
You can set other variables also in the session which you might need in profile_view
.
Do not think views, think code
def _student_profile(*arg_data, **kwarg_data):
context = do(arg_data, kwarg_data)
return render("my_template", context)
def student_profile(request, name=None, grade=None, student_id=None):
data = do_things(request)
data.update({"name": name, "grade": grade, "student_id": student_id})
return _student_profile(**data)
def process_query(request):
data = do_other_things(request)
return _student_profile(**data)