9👍
As docs say, runserver
isn’t meant as a deployment server. It also mentions that you probably can’t start it on port 80 unless you run it as root.
- [Django]-Django Celery – How to start a task with a delay of n – seconds – countdown flag is ignored
4👍
Here is the kind of file you will need to put in /etc/apache2/sites-enabled, you need to adjust the paths in it. You also need to load mod_wsgi which you can do via apt-get.
<VirtualHost 192.168.1.14:80>
ServerAdmin youremail@whatever.com
ServerName www.whatever.com
ServerAlias whatever.com
Alias /robots.txt /home/dimitris/Python/mysite/site_media/robots.txt
Alias /favicon.ico /home/dimitris/Python/mysite/site_media/favicon.png
Alias /static/ /home/dimitris/Python/mysite/site_media/static
WSGIDaemonProcess mysite user=dimitris processes=1 threads=5
WSGIProcessGroup mysite
WSGIScriptAlias / /home/dimitris/Python/mysite/deploy/mysqite_wsgi.py
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/mysite.error.log
CustomLog ${APACHE_LOG_DIR}/mysite.access.log combined
ServerSignature Off
</VirtualHost>
Most of this assumes you are running in a virtualenv, that means you will need a wsgi file to get things running. The above file sets up apache to run your “wsgi” file which looks something like this:
import os
from os.path import abspath, dirname, join
import sys
with open("/tmp/mysite.sys.path", "w") as f:
for i in sys.path:
f.write(i+"\n")
#redirect sys.stdout to sys.stderr for libraries that use
#print statements for optional import exceptions.
sys.stdout = sys.stderr
sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
sys.path.insert(0, abspath(join(dirname(__file__), "../../lib/python2.7/site-packages/")))
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
mod_wsgi, then opens this one file and executes it. application is the part that waits for requests from the webserver, and the rest behaves just like runserver except it can be multi-process and multi-threaded.
1👍
In the terminal while in a virtual environment, run:
sudo ./manage.py runserver 80
You will be asked for your password and it will run the server on port 80.
- [Django]-Locating file path from a <InMemoryUploadedFile> Django object
- [Django]-Django collectstatic on S3 uploads unchanged files everytime on Heroku
- [Django]-Django flatpages and images
0👍
The first , to create and active the virtual env:
python3 -m venv .venv
source .venv/bin/activate
second , install django :
pip install django
and run dev server with sudo:
sudo .venv/bin/python3 manage.py runserver 80
then open http://127.0.0.1/
- [Django]-Open() "/root/project/static/*.css" failed (13: Permission denied) nginx
- [Django]-Django middleware to determine user's group in a session
- [Django]-What is the settings for django rest framework swagger open api security object definition for oauth2 flow being password?
- [Django]-Django get_object_or_404 is not defined