如何将数据动态加载到Django模板中

时间:2019-05-23 21:25:44

标签: python django django-models django-templates

我正在尝试使用引导程序模式将数据动态加载到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)

0 个答案:

没有答案