如何将数据动态加载到Django temp

2024-09-22 16:35:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用引导模式将数据动态加载到django模板中。我现在所做的工作:

    def showprofile(full_name):
       return mentee.objects.filter(full_name="Katha Benterman")

但我希望能够动态加载数据,我发布了一个以前的问题,我已经尝试过了,但在我这边不起作用: How to display model fuction in Django template

当我在我的模型中尝试此代码时:

def showprofile(self,full_name):
       return self.objects.filter(full_name=fullname)

我得到这个错误showprofile() missing 1 required positional argument: 'full_name'

但我很困惑,因为当我试图通过自我,它说自我是没有定义的。你知道吗

有点搞不清楚发生了什么事,我们会通知你的!你知道吗

这是视图的外观:

def home(request):
    if request.method == 'GET':
        data = mentee.objects.all()
        profiles = mentee.showprofile(mentee.full_name, mentee.full_name)

        mentee_data = {
            "full_name": data,
            "email": data,
            "email": data,
            "phone" : data,
            "bio" : data,
            "gender" : data,
            "objectives" : data,
            "years_of_experience" : data,
            "university" : data,
            "graduation_year" : data,
            "major" : data,
            "class_standing" : data,
            "city" : data,
            "country" : data,
            "student_type" : data,
            "profile_pic" : data,
            "linkedin" : data,
            "GitHub" : data,
            "website" : data,
            "resume" : data,
            "area_of_concentration" : data,
            "roles_of_interest" : data,
            "show_profile": profiles

        }

        return render(request, 'main/index.html', mentee_data)

Tags: of数据nameselfdatareturnobjectsrequest