简体   繁体   English

为 Django 创建 Model

[英]Creating Model for Django

After following this Tutorial https://docs.djangoproject.com/en/3.0/intro/tutorial02/ i encountered a problem.在遵循本教程https://docs.djangoproject.com/en/3.0/intro/tutorial02/ 之后,我遇到了一个问题。 When i came to create my very first Model Django would refuse to do it.当我开始创建我的第一个 Model Django 时会拒绝这样做。 I have done it all.我都做了。 Django.setup() manage migrate make migrate and INSTALLED APPS. Django.setup() 管理 migrate make migrate 和 INSTALLED APPS。 My init is empty and settings is vanilla as it gets except with the extra entry for installed app.我的初始化是空的,设置是香草的,除了安装应用程序的额外条目。

This is my Project Structure.这是我的项目结构。 Picture图片

data.py数据.py

> from django.db import models
> 
> 
> class bill_table(models.Model):
>     number = models.CharField(primary_key=True)
>     name = models.CharField()
>     adres = models.CharField()
>     status = models.CharField()
>     money = models.IntegerField()
> 
> 
> class offer_table(models.Model):
>     number = models.CharField(primary_key=True)
>     name = models.CharField()
>     adres = models.CharField()
>     status = models.CharField()
>     money = models.IntegerField()

settings.py设置.py

> # Application definition 
> INSTALLED_APPS = [
>     'django.contrib.admin',
>     'django.contrib.auth',
>     'django.contrib.contenttypes',
>     'django.contrib.sessions',
>     'django.contrib.messages',
>     'django.contrib.staticfiles',
>     'data', ]

view.py视图.py

> import data
> 
> 
> def home(request):
>     return render(request, 'home.html', {'APP': render_to_string('dashboard.html')})
> 
> 
> def bill(request):
>     bills = data.bill_table.objects.all()
>     return render(
>         request, 'home.html',
>         {'APP': render_to_string(
>             'app/bill.html', {'title': 'Offerte',
>                               'status': 'status',
>                               'rows': bills}
>         )})

i am done with this framework if it makes it so hard to do simple tasks like this.如果这样的简单任务很难完成,我已经完成了这个框架。 In Flask at least it tells you whats wrong.在 Flask 中,至少它告诉你出了什么问题。 Even in witch line.甚至在巫师行。 What ever i do I will get an无论我做什么,我都会得到一个

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

or或者

RuntimeError: Model class data.bill_table doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

when i comment the Model out and remove all traces Django works again.当我评论 Model 并删除所有痕迹 Django 再次工作。 I am using the standart Template that come with PyCharm.我正在使用 PyCharm 附带的标准模板。 Django 3.0.5 Django 3.0.5

Your INSTALLED_APPS is commented out您的 INSTALLED_APPS 已被注释掉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM