I have this project directory structure:
.
.pylintrc
|--myproj .
|--myapp
|--myproj (settings.py is here)
__init__.py
manage.py
.
In settings.py, INSTALLED_APPS I have the first entry 'myapp'.
From the root folder (containing .pylintrc), I call
$ DJANGO_SETTINGS_MODULE=myproj.myproj.settings pylint myproj --load-plugins pylint_django
However, I get error no module named 'myapp'. If I change the INSTALLED_APPS entry to 'myproj.myapp', then it is able to continue, but now I'm unable to start the project normally with manage.py runserver.
pastebin myproj.settings
What am I doing wrong, and what can I do to proceed?
Likely your settings.py is improperly configured, you need to do something like this:
settings.py
INSTALLED_APPS = [
...
'myapp.apps.MyappConfig',
...
]
If you open the apps.py file in your myapp directory you'll see the config class that should be included in INSTALLED_APPS
The same problem happened to me and I find my solution.
In My Case, I missed my urls.py file.
re_path(r"^chaining/", include("smart_selects.urls")),
to
re_path(r"^chaining/", include("packages.smart_selects.urls")),
Related
EDIT
So this was a Docker issue, not a Python issue. Thank you everyone for your help!
I am working on a Django project. I have several apps within the project and everything has been working fine. I recently added a new app called files through django-admin and for some reason, Django cannot find this module. This is my project structure
core/
__init__.py
settings.py
urls.py
wsgi.py
api/
migrations/
__init__.py
admin.py
apps.py
models.py
urls.py
views.py
files/
__init__.py
apps.py
forms.py
init_s3.py
urls.py
views.py
The apps.py for the files module reads:
from django.apps import AppConfig
class FilesConfig(AppConfig):
name = 'files'
Which is almost word-for-word how the AppConfig for the api module is written:
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'api'
I have the api and files app installed in the INSTALLED_APPS setting:
INSTALLED_APPS = [
...other apps...
'api.apps.ApiConfig',
'files.apps.FilesConfig'
]
Django has no problems locating the api app, but cannot find the files app. When I run the server, I get the following error:
ModuleNotFoundError: No module named 'files'
What's going on here? What am I missing?
Any help is appreciated! Thanks!
Try putting the app name to INSTALLED_APPS:
INSTALLED_APPS = [
...other apps...
'files'
]
Have you checked your project's urls.py file? it should read:
urlpatterns = [
....
path('files/', include('files.urls')),
]
Good afternoon,
I'm new to Django and I'm trying to follow a tutorial. However, when running the server, the following error pops up:
File "C:\Users\Jorge\PycharmProjects\web\mysite\mysite\urls.py", line 18, in <module>
from myapp.views import *
ModuleNotFoundError: No module named 'myapp'
This is a screenshot about how my files are right now:
Your myapp folder should be inside in your mysite folder
Do the following:
Move myapp to C:\Users\Jorge\PycharmProjects\web\mysite\
In mysite\settings.py, add an entry as myapp.apps.MyappConfig in the INSTALLED_APPS list.
Now do python manage.py runserver from C:\Users\Jorge\PycharmProjects\web\mysite\.
Go to 'mysite' --> 'settings.py'
write as it is, Under
INSTALLED_APPS = [
'myapp',
I am following the Tango with Django book's tutorial.
I tried to do:
from rango import views
in tango_with_django_project/urls.py where rango is the application. The IDE I use is pycharm and it cannot find or doesn't recognize rango.
The folder hierarchy is as follow:
rango
__init__.py
...
views.py
tango_with_django_project
__init__.py
...
urls.py
I already added 'rango' in settings.py
INSTALLED_APPS = [
.......
'rango',
]
Any help or comment is greatly appreciated. Thank you.
You said
pycharm ... cannot find or doesn't recognize rango
but you don't say if you have actually tried running the application. It could be just that pycharm doesn't know where to look for the code.
Try setting the top level folder of your project (the one you have the tango_with_django_project folder in) and mark it as a "Sources Root" by right-clicking on the folder and selecting the option from the "Mark Directory As" menu.
If that doesn't work, run your django app and add any error messages to your question.
include rango in INSTALLED_APPS within settings.py file as mentioned in below snippet
INSTALLED_APPS = [
.......
'rango',
]
The problem has to do with the level of directory I opened in PyCharm.
When I had the problem, I opened it from the topmost directory - which was why PyCharm couldn't find it.
rangoFolder
tango_with_django_project
rango
__init__.py
...
views.py
tango_with_django_project
__init__.py
...
urls.py
When I opened the project from
tango_with_django_project
rango
__init__.py
...
views.py
tango_with_django_project
__init__.py
...
urls.py
It found the module rango.
Go to Preferences > Project Interpreter and set the project interpreter and path mapping. Also set the Project Structure accordingly.
I just started testing out PyCharm on my existing Django project, and it doesn't recognize any imports from apps within my project:
in my_app1/models.py:
from my_app2.models import thing
"Unresolved reference 'my_app2'"
Why is this? My project's directory structure matches the recommended layout, and it runs without errors, it's just PyCharm's magic doesn't want to work on it.
It seems related to this question:
Import app in django project
But I can't figure out what I am doing wrong. If I try:
from ..my_app2.models import thing
The PyCharm error goes away and it can auto predict, etc. But when I run the project Django throws:
ValueError: attempted relative import beyond top-level package
EDIT:
Project structure:
my_project/
src/
manage.py
db.sqlite3
my_app1/
templates/
__init.py__
admin.py
models.py
urls.py
views.py
...
my_app2/
templates/
__init.py__
admin.py
models.py
urls.py
views.py
...
my_project_app/
settings/
__init.py__
urls.py
...
I was having this issue using a "2 Scoops of Django" project layout, e.g.
/project_root
/project_dir
/config
/settings
/my_app
/tests
models.py
/requirements
readme.rst
The code was working, but in /tests, IntelliJ/PyCharm showed an unresolved reference:
from my_app.models import Something
I had all the __init__.py files in place. I ended up having to set the sources root to project_dir:
Right-click on project_dir, Mark Directory as > Sources Root
Now that I can take a look over you project structure I can tell you that the problem appears to be related to a missing __init__.py in your 'src' folder. Try adding an empty file named __init__.py in the root of 'src' folder.
Also, take a look to this question, I think is the same problem or a very similar one.
Hope this could be useful, cheers!
I was having this issue after I change my environment to virtualenv, so I changed my python interpreter to my current virtualenv.
Go to File > Settings > Project Interpreter.
In that window you would be able to see all packages includes on this interpreter, Django should be there.
This worked for me.
Link about: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206598665-Unresolved-Reference-Errors-for-django
I have a django project like:
virt_env_name/
project/
scripts_api/
__init__.py
scripts/
__init__.py
orders.py
api/
__init__.py
api.py
project/
settings.py
I am accessing the modules in order.py like:
from scripts_api.api.api import ClassA
from project.settings import Var1, Var2
but it is throwing the following error No module named for both imports.
How can I correct this?
NOTE: scripts_api is added in installed apps in settings.py. I thought it would help if scripts are in a django project application.
Go to setting.py and print the value of BASE_DIR
Runserver and check the terminal if the directory is the same as your working directory.
Because sometimes "No Module Found" error is raised due to BASE_DIR not being the correct one. Usually it is one or two folder outside or inside.
In your case, printing BASE_DIR should give a value like this for you to correctly access the modules:
abcd/pqrs/xyz/virtual_env_name/project
if the value doesn't ends the same way as above, then correct the BASE_DIR value in settings.py according to your requirement.