Yotam Yotam - 5 months ago 9
Python Question

setting setting apps value in django for a new application

So I've been following django tutorial and things worked well, but then I decided to try and write my own apps following the tutorial. I created a view, and updated the /

pysent/settings.py
file with this section

INSTALLED_APPS = [
'pressent.apps.PressentConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]


However, when I save the file, I get an error from the running server:

ImportError: No module named PressentConfig


If I change the first line above to only

`pressent`


I get no error message. On the other hand, with the tutorial example, things work with the line

polls.apps.PollsConfig


django
version is supposed to be 1.9.6

>>> import django
>>> django.VERSION
(1, 9, 6, 'final', 0)
>>>


What is going on here?

Edit
The solution was to edit
pysent/pressent/apps
and add

class PressentConfig(AppConfig):
name = 'pressent'


The reason to the problem was I changed the folder name.

Answer

I'm going to presume pressent is your django application name (project name I think is pysent), so there's a directory named pressent and inside it has a apps.py file, and finally that file has a class named PressentConfig.

PressentConfig class example:

from django.apps import AppConfig

class PressentConfig(AppConfig):
    name = 'pressent'

    # Exec some configs for this app. Maybe overriding the ready method
Comments