Installing Web Frameworks

Topics about the Software of Revolution Pi
Post Reply
momi88
Posts: 6
Joined: 15 Dec 2017, 16:55

Installing Web Frameworks

Post by momi88 »

Good Evening,

I'm really really new to RevPi and the Raspberry Pi world so maybe my question will sound strange for you all.
I know that it's possible to use python based web frameworks like Django and Flask on the Raspberry Pi...so my question is.....is it possible to install one of them on the RevPi as well?

Thank you so much for the help :)
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41

Re: Installing Web Frameworks

Post by volker »

Hi,
sorry but have not yet played around with that kind of framework - so I can't give you an answer. How about just trying to install it? Maybe some of our users have tried it and could answer your question.
Unser RevPi Motto: Don't just claim it - make it!
momi88
Posts: 6
Joined: 15 Dec 2017, 16:55

Re: Installing Web Frameworks

Post by momi88 »

Hi volker,

thank you for answering. If I had the device I would surely made a try but this is the problem, I don't have the device yet.
If someone could make this try for me and give me back a positive answer I would surely buy the device.
If I'd buy the RevPi and I wasn't able to install the web framework then It would become usless for my purpose.
If you, or someone else, could kindly try to install one of the framework I mentioned for me and give me a feedback it would be very appreciated.
After a few researches, I know that those frameworks work on Raspberry Pi so I suppose that they should work on RevPi as well.

Hope to see an answer very soon
Thank you so much
momi88
Posts: 6
Joined: 15 Dec 2017, 16:55

Re: Installing Web Frameworks

Post by momi88 »

Hi all!

Could anybody please try to install one of the frameworks I mentioned on a RevPi?
It should take just a few minutes. A positive response would lead me to purchase the device.

Thanks :)
User avatar
RevPiModIO
KUNBUS
Posts: 327
Joined: 20 Jan 2017, 08:44
Contact:

Re: Installing Web Frameworks

Post by RevPiModIO »

Hi momi88, it's a piece of cake :D

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 your wsgi.py !!!!
  • Create config
  • Activate config
  • Reload apache2
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
Screenshot_20171221_101629.png (131.68 KiB) Viewed 8917 times
Django is RUNNING :D - 404 is okay, we do not have an app right now, that's your work :P

Sven
python3-RevPiModIO - https://revpimodio.org/ || Der RevPi ist das Beste, was passieren konnte!
User avatar
pi_admin
Administrator
Posts: 115
Joined: 26 Aug 2016, 15:38

Re: Installing Web Frameworks

Post by pi_admin »

Hi Sven,

wow, thanks for testing.
momi88
Posts: 6
Joined: 15 Dec 2017, 16:55

Re: Installing Web Frameworks

Post by momi88 »

Wow Sven! That's impressive!

This is much more than I expected, you were very kind to do this for me. I don't know how to thank you!
I'm starting up an IoT project, but there are technology that I'm not very familiar with (like webs servers, web frameworks and so on) and I can't afford buying devices if don't know how they work or if they are not what I need.
The guide you provided me will be very useful in the next future.
Thank you so much, hope I'll be able to return the favor!

Best Regards
Post Reply