简体   繁体   中英

Creating Model for Django

After following this Tutorial https://docs.djangoproject.com/en/3.0/intro/tutorial02/ i encountered a problem. When i came to create my very first Model Django would refuse to do it. I have done it all. Django.setup() manage migrate make migrate and 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

> 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

> # 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

> 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. 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. I am using the standart Template that come with PyCharm. Django 3.0.5

Your INSTALLED_APPS is commented out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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