Hi momi88, it's a piece of cake
Install Django an use apache2 for a save productive environment! NEVER USE ./manage runserver FOR THAT - IT IS ONLY FOR DEVELOPMENT
Install Django on RevPi with apt (you can use pip, too)
Code: Select all
pi@RevPi0000:~ $ sudo apt-get install python3-django
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
python-django-common
Suggested packages:
python3-psycopg2 python3-mysqldb python3-flup python3-sqlite python3-memcache python3-bcrypt python3-yaml geoip-database-contrib gettext python-django-doc ipython3 bpython3 libgdal1
Recommended packages:
python3-sqlparse python3-tz
The following NEW packages will be installed:
python-django-common python3-django
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,482 kB of archives.
After this operation, 42.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-django-common all 1.7.11-1+deb8u2 [1,503 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-django all 1.7.11-1+deb8u2 [978 kB]
Fetched 2,482 kB in 4s (544 kB/s)
Selecting previously unselected package python-django-common.
(Reading database ... 86663 files and directories currently installed.)
Preparing to unpack .../python-django-common_1.7.11-1+deb8u2_all.deb ...
Unpacking python-django-common (1.7.11-1+deb8u2) ...
Selecting previously unselected package python3-django.
Preparing to unpack .../python3-django_1.7.11-1+deb8u2_all.deb ...
Unpacking python3-django (1.7.11-1+deb8u2) ...
Processing triggers for man-db (2.7.5-1~bpo8+1) ...
Setting up python-django-common (1.7.11-1+deb8u2) ...
Setting up python3-django (1.7.11-1+deb8u2) ...
Install WSGI for apache web server!
Code: Select all
pi@RevPi0000:~ $ sudo apt-get install libapache2-mod-wsgi-py3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libapache2-mod-wsgi-py3
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 75.6 kB of archives.
After this operation, 207 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libapache2-mod-wsgi-py3 armhf 4.3.0-1 [75.6 kB]
Fetched 75.6 kB in 1s (62.3 kB/s)
Selecting previously unselected package libapache2-mod-wsgi-py3.
(Reading database ... 98215 files and directories currently installed.)
Preparing to unpack .../libapache2-mod-wsgi-py3_4.3.0-1_armhf.deb ...
Unpacking libapache2-mod-wsgi-py3 (4.3.0-1) ...
Setting up libapache2-mod-wsgi-py3 (4.3.0-1) ...
apache2_invoke: Enable module wsgi
Create your project and use NOT /var/www (Kunbus did it not debian like and don't use a subfolder for their piCtory in /var/www
)
Use for example /var/www2
Code: Select all
pi@RevPi0000:/$ sudo mkdir /var/www2
pi@RevPi0000:/$ cd /var/www2
pi@RevPi0000:/var/www2$ sudo django-admin startproject mysite
pi@RevPi0000:/var/www2 $ cd mysite/
pi@RevPi0000:/var/www2/mysite $ sudo ./manage.py startapp mysiteapp
(do all you like to do with django )
Add the IP and/or Hostname of your RevPi to settings.py !!! If you do not, you'll get an "(400) Bad Request"
Code: Select all
pi@RevPi0000:/var/www2 $ sudo nano /var/www2/mysite/mysite/settings.py
# (...)
ALLOWED_HOSTS = [ "192.168.50.36" ]
# (...)
Configure apache with your project (do it debian like)
Edit the wsgi.py in your project! We add your project path dynamically to the sys.path, so apache/python can import it.
Code: Select all
pi@RevPi0000:/var/www2 $ sudo nano /var/www2/mysite/mysite/wsgi.py
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
# IMPORTANT - ADD THIS !!!
import sys
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
# ADD BLOCK END
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Apache config:
Code: Select all
pi@RevPi0000:~ $ sudo -s
root@RevPi0000:/home/pi# cat > /etc/apache2/conf-available/django-mysite.conf <<END
WSGIScriptAlias /mysite /var/www2/mysite/mysite/wsgi.py
<Directory /var/www2/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
END
root@RevPi0000:/home/pi# a2enconf django-mysite
Enabling conf django-mysite.
To activate the new configuration, you need to run:
service apache2 reload
root@RevPi0000:/home/pi# systemctl reload apache2
And than take your browser an go to your site http://ip_of_revpi/mysite
- Screenshot_20171221_101629.png (131.68 KiB) Viewed 9993 times
Django is RUNNING
- 404 is okay, we do not have an app right now, that's your work
Sven