17👍
Working with absolute imports in the view solved my issue. I changed .models to apfelschuss.votes.models.
Code that leads to runtime error:
from django.shortcuts import render
from .models import Voting
Issue solved with absolute import:
from django.shortcuts import render
from apfelschuss.votes.models import Voting
See commit on GitHub here.
20👍
When it says “Model class xxx doesn’t declare an explicit app_label” your models can specify Meta
to define their app_label
. You can also customise the database table name along with a bunch of other options as part of the meta data.
You need to do something like this on all your models;
class Author(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_picture = models.ImageField()
class Meta:
app_label = 'apfelschuss.votes'
def __str__(self):
return self.user.username
edit
I’ve checked out your repo & I think you’re over-complicating the project by having the users
and votes
apps under apfelschuss
.
I pulled them out to the root of the project & everything runs smoothly;
https://github.com/marksweb/apfelschuss/tree/so/questions/55553252
This is a more typical approach to project structure in django/python projects.
- How can I easily convert a Django app from mySQL to PostgreSQL?
- Django Help: AttributeError: 'module' object has no attribute 'Charfield'
- How do I hide the field label for a HiddenInput widget in Django Admin?
2👍
I’m using Python 3.7.5 on VS Code. This same issue was confusing me.
I went into the initially created project and found settings.py
Went to the section
INSTALLED_APPS = []
and added
'myapp.apps.MyappConfig'
, – make sure it’s cased correctly
this refers to the class in apps.py in the app causing issues
- No module named 'django.contrib.staticfiles.templatetags'
- Celery task and customize decorator
- Django, division between two annotate result won't calculate correctly
1👍
You have accidentally added your app name under MIDDLEWARE
section in settings.py
.
Spent some good time debugging, thought this might help save someone else’s time.
- How to install django for python 3.3
- Create JSON Response in Django with Model
- What does it mean for an object to be unscriptable?
- Querying Many to many fields in django template
- How to build sphinx documentation for django project
1👍
In file apps.py we see:
class ArticlesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Django.apps.articles'
We need name ‘Django.apps.articles’
Now write in terminal:
from Django.apps.articles.models import Article
And all working! I ran into this problem in PyCharm.
0👍
I had the same error and fixed it by adding a missing __init__.py
file (just a blank file) to my main module inside my project root.
~/my_project
foo/
models.py
tests.py
__init__.py # <-- Added an empty __init__.py here
- Multiple file upload DRF
- Testing authentication in Django Rest Framework Views — Cannot authenticate when testing
- Django admin how to display widget on readonly field
- Custom user model in django
- How to dynamically add EC2 ip addresses to Django ALLOWED_HOSTS