0

Help please! am new to django please i have installed django in virtual environment i created on my desktop. but whenever i create a django project and open up the folder in vs code in the url.py file and the wsgi.py files there is a red underline in the import statements. and when i hover over it it says unable to import the package name

this is from the wsgi.py file. it says unable to import django.core.wsgi i have not written any code so there are no errors yet but vscode shows a red underline on the from import statements

from django.core.wsgi import get_wsgi_application

also in the urls.py file it does the same thing

from django.contrib import admin
from django.urls import path

i have tried uninstalling and installing django again but it didn't work. it still does the samething

ps. i have not written any code in the django project prior to this but no doubt this will surely give me an error

  • Can you show us what exactly is the output? Please do the following in your app please type in `python manage.py shell` then `'from django.core.wsgi import get_wsgi_application` what happens? – A I Jun 22 '20 at 12:49
  • It's likely your VS Code cannot find the virtual environment where you have Django installed. Check the answers to [this question](https://stackoverflow.com/questions/54106071/how-to-setup-virtual-environment-for-python-in-vs-code) – MattRowbum Jun 22 '20 at 13:09

1 Answers1

1

This has to do with your starting project because Django can't import the initial files. You're doing something wrong to install, without a doubt.

Make sure to install Django within the virtual env that you've created and use the Django-admin start project command to install Django

virtualenv projectname

Activate virtualenv

Next to your folder for virtualenv write in command

pip install Django. 

Note the dot at the end, required to start a project within the folder you're currently in but next to your virtualenv folder

Now it should install Django within env

Next, run

python manage.py check

If all okay

python manage.py runserver

Also check your naming of project

  • the problem was that i didn't open the file containing the virtual environment and the django project in vscode. i only opened the file that django project file. It worked as soon as i opened the parent file in vs code.(the file that had both the virtual_env file ant the django project file – Nwafor Sopuru Jun 25 '20 at 09:35