How do I pass variables from one view to another and render with the last view's URL in Django?

前端 未结 2 1606
青春惊慌失措
青春惊慌失措 2020-12-10 08:22

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&

2条回答
  •  被撕碎了的回忆
    2020-12-10 08:39

    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)
    

提交回复
热议问题