30๐
I guess the sudo command will run the process in the superuser context, and the superuser context lack virtualenv settings.
You may try to call the python binary at your virtualenv explicitly, for example:
sudo $(which python) manage.py runserver 0.0.0.0:80
Make a shell script to set the virtualenv and call manage.py runserver
, then sudo this script instead.
#!/bin/bash
source /home/darwin/.virtualenvs/foo/bin/activate
cd /path/to/project/foo
python manage.py runserver 0.0.0.0:80
Replace /home/darwin/.virtualenvs/foo
with the root of your actual virtualenv and /path/to/project/foo
with the root of your project.
8๐
Hereโs another solution, instead of creating shell script, just specify which python executable you want to use in the command:
Assuming that your virtualenv container is called .virtualenvs
and thereโs an env called myproject
in it, this is command you have to write:
$ sudo ~/.virtualenvs/myproject/bin/python manage.py runserver 0.0.0.0:80
- Django annotate and count: how to filter the ones to include in count
- Using django models across apps?
- Django, Apache2 on Google Kubernetes Engine writing Opencensus Traces to Stackdriver Trace
- ModelViewSet โ Update nested field
1๐
Building upon @Paulo_Scardineโs anwser:
If you want to keep your virtualenv environment variables, you can add the -E
option to the sudo
command:
sudo -E $(which python) manage.py runserver 0.0.0.0:80
0๐
Hereโs another solution, instead of creating shell script, just specify which python executable you want to use in the command:
Assuming that your virtualenv container is called venv in your project home directory, this is command you have to write:
sudo /home/mahome/PycharmProjects/sampleproject/venv/bin/python manage.py runserver 127.0.1.1:80
- Django REST Framework: Validate before a delete
- Zip File downloaded from ReactJs/Axios is corrupted
- How to use ModelMultipleChoiceFilter?
-1๐
Run
manage.py runserver 0.0.0.0:8000
ie. run the server in different port and not the default port 80
while accessing the url use the port number
- Django vs. Pylons
- How to manage.py loaddata in Django
- Django GROUP BY field value
- Django and Shibboleth