25👍
You need to add an empty __init__.py
(4 underscores in total) file in the apps
folder for it to be recognized by Python as a package.
Have a look at the documentation for more informations.
14👍
This can also happen if you installed your app in settings.py
in your main project folder, before running this:
python manage.py startapp [app-name]
Comment it out, create the app (should work now), then put the line back into the settings.py
file and continue on.
- [Django]-Sublime Text 2 & 3 setup for python / django with code completion
- [Django]-How to see details of Django errors with Gunicorn?
- [Django]-Django {% if forloop.first %} question
11👍
Note that in Django 1.9 there is a module called django.apps
Avoiding name clashes with built-in modules is generally advised
- [Django]-Django and Bootstrap: What app is recommended?
- [Django]-Django filter events occurring today
- [Django]-What does request.method == "POST" mean in Django?
11👍
If you’ve used the django-admin startapp myapp
command, it creates this file: myapp/apps.py
.
It could be conflicting with your apps/
module folder. A hidden apps.pyc
file could be in your myapp/
folder.
Try removing these:
project/apps/myapp/apps.py
project/apps/myapp/apps.pyc
- [Django]-Django Reverse Accessor Clashes
- [Django]-Django test VS pytest
- [Django]-How do I use allow_tags in django 2.0 admin?
4👍
It might be a comma missing after your config path:
INSTALLED_APPS = [
'palc.apps.PalcConfig', # This comma
'django.contrib.admin',
...]
- [Django]-Profiling Django
- [Django]-WARNING: Running pip as the 'root' user
- [Django]-VueJS + Django Channels
3👍
Note that in Django 1.9
, you can add your app into the INSTALLED_APPS
list.
If your app name is app
and you have created models in it, then go to the settings.py
file and add your app:
INSTALLED_APPS = [
...
'app'
]
- [Django]-Django's timezone.now does not show the right time
- [Django]-Cancel an already executing task with Celery?
- [Django]-Python Requests POST doing a GET?
2👍
First, check your manage.py
and make sure it has the correct reference to myapp
.
…apps/myapp/manage.py
...
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
...
If the settings are correct, check the Python interpreter. If you’re using virtualenv, errors can occur when you use the global Python instead of the virtual environment. The use of global Python can be caused by improperly setting up your IDE, user error or incorrect bin/bash in manage.py
.
To make sure manage.py
is running on the virtual env, check the first line in manage.py
. By default the file reads:
#!/usr/bin python
Change that to:
#!/path/to/virtualenv/bin python
Now, check the Terminal and what Python version it’s using. Then, activate the virtualenv:
[user@pc] #: source /path/to/virtualenv/bin/activate
(venv) [user@pc] #: pip list
Confirm Django is installed. If it is and it’s still not working correctly, then upgrade it with pip
:
(venv) [user@pc] #: pip install --upgrade django
If none of the above works even though the Python version is correct, you’re using the right Python environment and manage.py
is set up correctly, then that means the error is somewhere else.
- [Django]-Django Queryset only() and defer()
- [Django]-Returning data on POST in django-tastypie
- [Django]-Search by foreign key id in admin
1👍
For people who are here becuase adding a new view and bumped into this problem I did the above desceribed by aumo For me worked adding a empty init.py inside my folder view and inside the folder I was adding eg.
-- example-folder
-- views
-- `__init.py__`
-- `index.py`
-- `__init.py__`
-- `urls.py`
hope makes sense
- [Django]-No module named django but it is installed
- [Django]-Command "django-admin.py startproject mysite" not recognized
- [Django]-How does pgBouncer help to speed up Django
0👍
Command: python manage.py startapp app_name
Class name must be the same as app_name
in models.py
file and then add your app_name
in the INSTALLED_APPS
list in settings.py
.
- [Django]-Django how to pass custom variables to context to use in custom admin template?
- [Django]-Should I avoid multi-table (concrete) inheritance in Django by any means?
- [Django]-Filter Queryset on empty ImageField
0👍
If you use this command to start an app:
django-admin startapp appexample
…then, the AppexampleConfig
class should not be listed in the settings.py
file.
Just add the app name (e.g. appexample
) in INSTALLED_APPS
list. Avoid using: appexample.app.AppexampleConfig
.
Usually, the AppexampleConfig
class is a subclass of the django.apps.Appconfig
class that represents a Django application and its configuration. It just defines the name class attribute and sets its value to Appexample
.
- [Django]-Django Models (1054, "Unknown column in 'field list'")
- [Django]-Django test FileField using test fixtures
- [Django]-How to check (in template) if user belongs to a group
0👍
I got past this issue after running python3 manage.py runserver
instead of python manage.py runserver
Wasted a solid 25 minutes on that one…
- [Django]-How to make the foreign key field optional in Django model?
- [Django]-Django Standalone Script
- [Django]-Threaded Django task doesn't automatically handle transactions or db connections?
0👍
Please make that your app is in the root directory of your project. By this I mean if by mistake you start an app outside your main directory, Django will not be able to find your app and the only solution is to move it to your project’s main directory. The screenshots show how to fix the problem
enter image description here
the first images show the wish also prompts this error that your apps are not loaded yet when you run the app.
The second screenshot shows how to fix the problem.
enter image description here
This is what I mean that the app should be in the same directory of the main project. In my case my main directory is crmapp.
- [Django]-Turn off SQL logging while keeping settings.DEBUG?
- [Django]-Django check if object in ManyToMany field
- [Django]-Django query where in
0👍
I had exactly the same issue.
In settings.py I printed the SYS path by:
import sys
print(sys.path)
It turned out that main path to the project directory was not included, so I had to add it manually here.
import sys
sys.path.append(<path to my main project dir>)
- [Django]-How to process a form (via get or post) using class-based views?
- [Django]-Django model blank=False does not work?
- [Django]-How to return generated file download with Django REST Framework?
0👍
Had a similar issue with Django 3.1.5.
Solved it by deleting all __pycache__
folders in the project.
- [Django]-Django count RawQuerySet
- [Django]-Specify Django Test Database names in settings.py
- [Django]-Django: Use of DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT in settings.py?
0👍
another possible cause for this is if the Django app in question was created somewhere ‘outside’ the project root. E.g., executing:
project_root/manage.py startapp search
, I didn’t realize that my Django app was created in the current folder, not inside the project root (in my case, named just that, ‘project_root’, haha). Django conventions dictate that the app, referenced in this case by ‘search’ in INSTALLED_APPS inside settings.py, should be on the BASE_DIR (project_root in my case).
- [Django]-How to get getting base_url in django template
- [Django]-Python: Memory leak debugging
- [Django]-Are there any plans to officially support Django with IIS?
0👍
if you are using Docker for deploying your application with default command like:
uwsgi --socket=0.0.0.0:9000 --module=myapp.wsgi:application --py-autoreload=1
make sure to change your working directory in the end of Dockerfile like:
WORKDIR /absolute/path/to/source/code
- [Django]-Django 1.7 – How do I suppress "(1_6.W001) Some project unittests may not execute as expected."?
- [Django]-Django ModelForm override widget
- [Django]-Django: invalid literal for int() with base 10
0👍
Go to the virtual enviroment and upgrade your django using command pip install --upgrade Django
- [Django]-Empty Request.FILES with Django Upload forms
- [Django]-'SSLError' installing with pip
- [Django]-How to reset the sequence for IDs on PostgreSQL tables
0👍
Make sure you first execute python manage.py startapp app_name
and then add app_name into settings.py
- [Django]-Django error when installing Graphite – settings.DATABASES is improperly configured. Please supply the ENGINE value
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Django default_from_email name
0👍
When executing (in TERMINAL)
python manage.py startapp (your_app_name)
First check apps.py in (your_app_name) folder.
It should be something like this:
class (__auto_generated__)Config(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = '(your_app_name')
Second check settings.py, in INSTALLED_APPS['']
, you must have ‘your_app_name’
Be careful when you change your app names
- [Django]-Django: save() vs update() to update the database?
- [Django]-Django request get parameters
- [Django]-Creating a dynamic choice field
0👍
I had the same issue and I fixed it by adding sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
to manage.py
file:
def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
# ⬇️⬇️⬇️ HERE ⬇️⬇️⬇️
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
execute_from_command_line(sys.argv)
- [Django]-How to I show a list of ForeignKey reverse lookups in the DJango admin interface?
- [Django]-Why is factory_boy superior to using the ORM directly in tests?
- [Django]-Django – specify which model manager Django admin should use
- [Django]-Django: how save bytes object to models.FileField?
- [Django]-Django models avoid duplicates
- [Django]-Clearing specific cache in Django