Home > front end >  ModuleNotFoundError: No module named 'config.wsgi'
ModuleNotFoundError: No module named 'config.wsgi'

Time:11-19

I'm trying to run a .py file and in the file I have this import

from config.wsgi import *
import os
from django.template.loader import get_template
from weasyprint import HTML, CSS
from config import settings

The whole project works, if I set runserver, the project starts without any problem, but this file does not work. The structure of the project is as follows

NombreDelProyecto
--app
---config
----__init__.py
----asgi.py
----settings.py
----wsgy.py
----db.py
---core
----general
----login
----user
----archivodetest.py

the case as I say the project works, but in the views of the applications that I have been doing to put imports I get in red underlined but as I say it works for example:

from core.general.forms import ActividadForm

That comes out in red, if I put in front of the core, app.core as follows

from app.core.general.forms import ActividadForm

it does not show red but the project does not work and I get the following error

from app.core.general.forms import ActividadForm
ModuleNotFoundError: No module named 'app'

I understand that it is the routes or something I did wrong from the beginning, please could someone help me.

Thank you very much.

I tried adding the route, changing the app's route in settings, but to no avail.

CodePudding user response:

You've named the file wsgy.py but it needs to be wsgi.py.

Rename your file in config and retry.

To your question, I think its because you're missing the __init__.py file in the general app.

If you haven't already go one, you'll likely need to have add the same again in your core app too.

You probably manually created all of these files and structures I suspect, and if that's the case, please take a look at the documentation regarding creating new apps inside a django project.

If you go a bit further up the page, it will also tell you how to create the initial django project structure with a command.

CodePudding user response:

Thank you very much for the answer, I managed to solve it after a lot of testing. There are two ways, open the project again from the app folder (I had it open in the ProjectName folder). Or as a second option in pyCharm on the left where the project folders are, I went to the app folder (which is the root) and right clicked and in the menu, Mark Directorie as - Sources root. Then my problem is fixed. I had all the arcvhiso init.py, and where I put the wrong name wsgi.py is that I wrote it wrong here but in the project it was right. Thank you very much for the help.

  • Related