Question

How to run this command in wsgi.py file in django?

How to run this command in wsgi.py file in django

My wsgi.py files looks like

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_project.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My Command that i want to add in wsgi.py file

python manage.py runserver 127.0.0.1:8000

I want to run this command using wsgi.py file how to add this command into it.

Thanks :)

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

If you want wsgi.py to execute the command python manage.py runserver 127.0.0.1:8000 as a shell command, you can use something like this:

import os
from subprocess import call
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_project.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
call('python manage.py runserver 127.0.0.1:8000')

But I wouldn’t recommend doing it this way, If you are using apache or nginx to serve the django site and if you need to access it locally, you can make your website listen on *:80.

Use nano.

So the command would be:

nano wsgi.py

Make sure you call the command in the directory the wsgi.py file is in.

Once the file is open, add the line to the end of the file. Then save with Ctrl-o, hit Enter to save the filename, and exit out of nano with Ctrl-x.

You can also append the line to the end of the file:

echo "python manage.py runserver 127.0.0.1:8000" >> wsgi.py

Then from the command line run

python3 wsgi.py

or

python wsgi.py

…depending on your Python versions and settings.