小编Shu*_*aha的帖子

检索数据时显示“无法获得 <class 'django.db.models.query.QuerySet'> 的 repr”

我一直在尝试从模型StudentInfo检索所有数据。但它显示以下错误。

django.db.utils.ProgrammingError:列 student_studentinfo.gurdians_mobile 不存在 allStudent
格式错误:ProgrammingError:列 student_studentinfo.gurdians_mobile 不存在 LINE 1: ...ile_no1", "student_studentinfo"."current_address", "student_s.. .

调试我的代码后,我发现导致错误的行是

allStudent = StudentInfo.objects.all()

调试消息显示:

无法获得类“django.db.models.query.QuerySet”的代表

这是我的模型StudentInfo

class StudentInfo(models.Model):
    student_name = models.CharField("Student Name",max_length=20)
    admission_date = models.DateField("Admission Date")
    mobile_no1 = models.CharField("Mobile No.",max_length=12)
    current_address = models.CharField("Current Address",max_length=20,blank=True)
    batch_number = models.ForeignKey(BatchInfo)
    coaching_id = models.IntegerField("Coaching ID")

    def __unicode__(self):
        return self.student_name

    def __repr__(self):
        return str(self.student_name)
Run Code Online (Sandbox Code Playgroud)

以及与StudentInfo相关的另一个模型BatchInfo

class BatchInfo(models.Model):
    batch_name = models.CharField("Batch Name",max_length=20)
    batch_started_from = models.DateField("Batch Started From")
    no_of_registered_student = models.IntegerField("Number of Registered Student so far",default=0) …
Run Code Online (Sandbox Code Playgroud)

python django django-models python-3.x

5
推荐指数
1
解决办法
1万
查看次数

Django:重定向到带参数的查看

我正在使用 Django 身份验证。每当用户登录时,我想将他重定向到 /profile/user_id,将 user_id 设为一个数字。我可以通过request.user.profile.id. 在 settings.py 我有LOGIN_REDIRECT_URL = 'app_1:index'

app_1/urls.py:

url(r'^profile/$', views.index, name='index'),
# ex: /profile/5/
url(r'^profile/(?P<user_id>[0-9]+)/$', views.profile, name='profile'),
Run Code Online (Sandbox Code Playgroud)

app_1/views.py(我也尝试过的东西被评论了):

def index(request):
    userid = request.user.profile.id
    #return render(request, 'app_1/index.html', context)
    #return profile(request, request.user.profile.id)
    #return render(request, 'app_1/user_prof.html', {'user': request.user.profile.id})
    #return redirect(profile, user_id= request.user.profile.id)
    return redirect('profile', user_id=userid)


def profile(request, user_id):
    user = get_object_or_404(Profile, pk=user_id)
    return render(request, 'app_1/user_prof.html', {'user': user})
Run Code Online (Sandbox Code Playgroud)

我一定遗漏了一些东西,因为这应该很容易,但我一直坚持下去。提前致谢。

编辑:我得到的错误是Reverse for 'profile' not found. 'profile' is not a valid view function or pattern name.http …

python authentication django

2
推荐指数
1
解决办法
1万
查看次数