By Gopal Raha
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 :)
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!
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.
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.