django过滤器表单未显示

pzfprimi  于 2023-01-18  发布在  Go
关注(0)|答案(1)|浏览(174)

django过滤器表单不显示它应该显示一个表单但只显示提交按钮
models.py:

class Profile(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE,null=True)
    bio = models.TextField()
    phone_number = models.IntegerField(blank=True, null=True)
    Birth_date = models.DateField(blank=True, null=True)
    age = models.IntegerField(blank=True, null=True)
    education = models.TextField(blank=True, null=True,max_length=45)
    WorkType = models.CharField(blank=True, null=True,max_length=150)
    desired_wage = models.IntegerField(blank=True, null=True)
    location = models.CharField(blank=True, null=True,max_length=25)
    gender = models.PositiveSmallIntegerField(blank=True, null=True,choices=GENDER_CHOICES)

    def __str__(self):
        return str(self.user) if self.user else ''

视图:

def ListingsPage(request):
    Profile = Profile.objects.all()
    profile_filter = ProfileFilter(request.GET,queryset=Profile)
    profile = profile_filter.qs
    context = {
        "filter":profile_filter,
        "profile":Profile,
        }
    return render(request,"base/Listings.html",context)

filters.py:

import django_filters

from .models import Profile

class ProfileFilter(django_filters.FilterSet):
    class Meta:
        model = Profile
        fields = ['bio','location']

温度:

<div>
  <form method="GET" action="{% url 'listings' %}">
    {{filter.form}}
    <button type="submit" value="Submit">Submit</button>
  </form>
</div>

它应该显示一种形式,它没有

iklwldmw

iklwldmw1#

您在profile查询集中有这样的拼写错误...
您需要写入Profile而不是profile

def ListingsPage(request):
    Profile = Profile.objects.all()
    profile_filter = ProfileFilter(request.GET,queryset=Profile)
    Profile = profile_filter.qs # <--------- this correction need
    context = {
        "filter":profile_filter,
        "profile":Profile,
        }
    return render(request,"base/Listings.html",context)

相关问题