吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1084|回复: 4
收起左侧

[求助] python,DJango模块的引入问题

[复制链接]
feng0945 发表于 2021-5-14 10:32
我把from app.models import Record 放在代码头部就无法调用,网页报错type object 'Record' has no attribute 'objects'。但是放到def里面就可以调用正常。
求各位大佬能告诉一下我这个是什么原因和如何解决的方法。我用的是python 3.8.5和Django 3.1.7。代码如下:
# coding:utf-8
from django.shortcuts import render, redirect, reverse
from django.views import View
class Record(View):
    TEMPLATE = 'record/record.html'
    DEPARTMENT = (
        ('NULL', '请选择部门', '')
    def get(self, request):
       from app.models import Record
        record = Record.objects.all()
        return render(request, self.TEMPLATE, {'msg1': self.DEPARTMENT, 'record': record} )


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

jami1024 发表于 2021-5-14 11:03
你的class Record(View) 和from app.models import Record 重复了。建议换个名字
zchamei 发表于 2021-5-14 11:22
 楼主| feng0945 发表于 2021-5-14 12:38
jami1024 发表于 2021-5-14 11:03
你的class Record(View) 和from app.models import Record 重复了。建议换个名字

我发现了,谢谢大佬。
gentlespider 发表于 2021-5-14 15:05
变量名取得好
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-15 15:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表