python manage.py runserver not working or showing errors

186 Views Asked by At

Ive set up django on a virtual env and im trying to run it. I've made sure that python is installed and that my virtual env is activated. I created a django project "my_site" with the command django-admin startproject my_site . The virtual env is "my_env" This is my project directory: enter image description here In the command terminal when i run python migrate.py runserver nothing happens, the server crashes with no error message and i am not able to access localhost 8000

(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> python manage.py runserver
          Watching for file changes with StatReloader
          Performing system checks...
          System check identified no issues (0 silenced).
(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> 

This is the output for pip list :

(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> pip list
Package            Version
------------------ -------
asgiref            3.7.2
backports.zoneinfo 0.2.1
Django             4.2.8
pip                20.2.3
setuptools         49.2.1
sqlparse           0.4.4
typing-extensions  4.9.0
tzdata             2023.4
WARNING: You are using pip version 20.2.3; however, version 23.3.2 is available.
You should consider upgrading via the 'c:\users\ananya\onedrive\desktop\django\my_env\scripts\python.exe -m pip install --upgrade pip' command.        
(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> 

This is the output for pip show Django :

(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> pip show django
Name: Django
Version: 4.2.8
Summary: A high-level Python web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: [email protected]
License: BSD-3-Clause
Location: c:\users\ananya\onedrive\desktop\django\my_env\lib\site-packages
Requires: sqlparse, asgiref, backports.zoneinfo, tzdata
Required-by:
(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django>

This is my python and django version

(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> python --version
Python 3.8.8
(my_env) PS C:\Users\Ananya\OneDrive\Desktop\django> python -m django --version
4.2.8

I tried running : python C:\Users\Ananya\OneDrive\Desktop\django\manage.py runserver , I tried deleting and creating a new env . i was expecting the terminal output to be something like : image where i can be directed to localhost 8000

3

There are 3 best solutions below

1
Pycm On

Don't move folders manually in django projects. (unless your know what you are doing)

Your folder structure should be like this.

Env
   Django_project_name
   (terminal should move in to this folder) 

       manage.py
       sqlite.db
       Django_project_name
           settings.py
           urls.py

Your terminal should move in to "my_site" folder.

Run

cd my_site

Then run "migrations" and "runserver".

Only creat project command can run outside, All the other django commands should run inside your django project folder, where manage.py file is. Use

cd my_site

To change the terminal location.

So below is the normal procedure.

  1. Run create project command
  2. Move into project folder / you must move it to this folder using "cd project_name"
  3. Run migrations
  4. Run server
  5. try accessing 127.0.0.1:8000 in your browser

use

python manage.py runserver

or

python3 manage.py runserver

0
cyclonegiorno On

If you have pressed Ctrl + C while copying localhost, the server will terminate.

0
Ananya On

So i resolved the error by simply deleting python and anaconda and re installing python