Тёмный

How to turn your Raspberry Pi into a Flask App Server 

Nazmus Nasir
Подписаться 10 тыс.
Просмотров 27 тыс.
50% 1

Welcome to the another Raspberry Pi Tutorial! Today I'll show you how to install Flask on your Raspberry Pi and turn it into an application server.
This is a follow up to the last tutorial where I showed you how to install Apache. These two can be followed independently but you'd need both before the next video.
This is the next step to controlling an LED from your browser!
Please also see the following link at EasyProgramming.net for more information on the project itself: www.easyprogra...
I hope you enjoy the tutorial!
Have questions? Ask below or on EasyProgramming.net!
#RaspberryPi #Flask #TechTutorials
-----------
Visit my website: www.easyprogra...
Subscribe on RU-vid: / nazmusnasir
Support me on Patreon: / nazmus
Follow me on Twitter: / nazteroid
Like me on Facebook: / easyprogrammingnet
Check out my Github: github.com/naz...

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 28   
@celines.5940
@celines.5940 2 года назад
Great tutorial! Worked on the first try for me 🥳
@Baba-so6fh
@Baba-so6fh 3 года назад
How can you leave flask running in the background so you can use the pi for other stuff?
@naztronaut
@naztronaut 3 года назад
You can run it with nohup which will run it in the background OR (preferred) You can run it behind Apache and let Apache maintain it. Tutorial here: www.easyprogramming.net/raspberrypi/pi_flask_apache.php If you need to take a step back and learn how to install apache: www.easyprogramming.net/raspberrypi/pi_apache_web_server.php I have a bunch more projects on the site and most of them use Flask running in the background, maintained by Apache. Feel free to check them out.
@Lunolux
@Lunolux 3 года назад
nice actually that mean i can have several website hosted in the raspberry pi ?? i start coding one month ago in python (django) and now i host it in online using heroku to test hope to get my raspberry as soon as possible thx for the video, very helpful
@naztronaut
@naztronaut 3 года назад
Yup! You can host as many websites as you can until your Pi starts running out of Memory/space. Python is super fun, hope you're having fun learning. Heroku skills is also really good to have. Good luck with your project!
@phillip4833
@phillip4833 4 года назад
I have a few questions and trying to accomplish a few things while using flask
@naztronaut
@naztronaut 4 года назад
Sure, ask away! I'll try my best to help.
@phillip4833
@phillip4833 4 года назад
@@naztronaut The first one that comes to mind is that once you creates a virtual environment, could I take that folder and more it across to another Rpi?
@naztronaut
@naztronaut 4 года назад
@@phillip4833 Hey there, sorry I missed your question last week. venv in Python is wonky when you move it from one directory to another, let alone one Pi to another. It's best to just set it up again, should only take a couple of minutes. The reason behind this is when a venv is created, the paths are often hard coded somewhere in the environment. So when you move it, the path doesn't change. It's a little annoying but not much you can do at this point, unless they make huge changes. This is also why you should never push your venv into GitHub or any other versioning system, because it won't work for anyone who clones/pulls the repository. Hope that makes sense!
@phillip4833
@phillip4833 4 года назад
@@naztronaut yes that make sense and I believe i ran into this problem lol
@tpz1474
@tpz1474 4 года назад
Thanks for this tutorial! How are we able to access the Flask application server on another computer, outside of the raspberry Pi? Also, is it possible to access this on a computer over the internet?
@naztronaut
@naztronaut 4 года назад
Hi Eugene, Glad this was helpful! To access the Flask app on another computer, just put in the Pi's IP address into your browser. So if you ssh into your pi as 192.168.1.123, then go to 192.168.1.123:5000 and you should be able to access the site. If you don't want to access it using the port (:5000) then you can run it behind Apache or another web server. I have a guide on how to do that as well here: www.easyprogramming.net/raspberrypi/pi_flask_app_server.php You CAN make it accessible over the internet, but I wouldn't recommend it. To make it available, you'd need to set up port forwarding on your router and allow traffic to come through that port into your Pi. Unless you have your network locked down and take a whole lot of precautions, I would advise against making it available online, because hackers are always sniffing for these open ports and this could allow them easy access to your whole home network. If you need to access it externally, I recommend setting up a VPN. You can set up PiVPN that'll keep your connection secure. And I do have a tutorial on that as well: www.easyprogramming.net/raspberrypi/pivpn_pihole.php Good luck!
@gcobanimkontwana4909
@gcobanimkontwana4909 4 года назад
No such file is found. i am at this directory /var/www/pipApp. When i try this command .venv/bin/activate it shows that message. what could be the reason?
@gcobanimkontwana4909
@gcobanimkontwana4909 4 года назад
i ran some command here and was successfully. i cant seem to have @app.route. how do i use this sign inside my nano file?
@naztronaut
@naztronaut 4 года назад
@@gcobanimkontwana4909 What does your code look like? have you copied/pasted from my example?
@gcobanimkontwana4909
@gcobanimkontwana4909 4 года назад
@@naztronaut i have but on flask run --host=0.0.0.0 already in use or 404 Error
@naztronaut
@naztronaut 4 года назад
@@gcobanimkontwana4909 Did you do "export FLASK_APP=hello.py" first? Check out the written steps here: www.easyprogramming.net/raspberrypi/pi_flask_app_server.php
@gcobanimkontwana4909
@gcobanimkontwana4909 4 года назад
How to copy over that code to nano hello.py, Ctrl+ C but to paste over i am struggling please assist as to how. Because now i am getting this issue, name is not defined in line 2. @app.route how to use it?
@naztronaut
@naztronaut 4 года назад
In cmd line, select something with your mouse to copy, and then right-click to paste. What does your hello.py look like?
@victorga74
@victorga74 2 года назад
Thanks for sharing, is an excellent tutorial 👏
@annikat.2244
@annikat.2244 4 года назад
Maybe it only worked for my settings, but I was able to download flask with just adding sudo in the front. It also seemed to be useless to deactivate venv, because I could update the ownerstatus while in venv (i checked whether it was gone when deactivating, it wasn't) Just for quickness:)
@naztronaut
@naztronaut 4 года назад
That's good to know, thank you! It may be an environmental thing or just how things are initially set up. I only have 'deactivate' in there before changing owner status is because during test runs I've occasionally run into issues where the permissions weren't set correct because I was in venv.
@ajayjoseph4498
@ajayjoseph4498 3 года назад
Absolutely brilliant! I will be binge-watching your videos.
@naztronaut
@naztronaut 3 года назад
Thank you
@djtyros
@djtyros 3 года назад
COMMAND NOT FOUND ...If anyone else gets this issue at 4:20, type "source venv/bin/activate" This will get you into the virtual environment, so you can proceed. And at 7:30 "python -m flask run" .... if you're getting "-bash: flask: command not found", even if you're sure its installed.
@naztronaut
@naztronaut 3 года назад
You can do 'source' or just a dot like I did in the video: . venv/bin/activate And if you're in an virtual environment, install flask as shown in 6:34 - pip install flask (or pip3 install flask) so that you don't have to keep running it with 'python -m'. Make sure you're in your virtual environment when you do it. The command not found error can happen if you install it in a venv but didn't activate it or you installed it globally and your venv can't access it. The written tutorial also has all these steps: www.easyprogramming.net/raspberrypi/pi_flask_app_server.php
@weibinyu
@weibinyu 3 года назад
the easiest way to do it is, go into the bin folder and then type ". activate".
@naztronaut
@naztronaut 3 года назад
@@weibinyu It's the same as: . venv/bin/activate Minus the extra step of going into bin folder.
Далее
Barno
00:22
Просмотров 538 тыс.
titan tvman's plan (skibidi toilet 77)
01:00
Просмотров 4,4 млн
Controlling LED's with Flask Raspberry Pi
11:54
Просмотров 1,7 тыс.
How to Install an Apache Web Server on Raspberry Pi
7:38
Raspberry Pi - Control an LED from a browser
12:06
Просмотров 26 тыс.
Power Apps Model Driven Apps FULL COURSE for Beginners
3:23:34
PiVPN : How to Run a VPN Server on a $35 Raspberry Pi!
35:06
I Turned A Raspberry Pi Into A Node.js Web Server
7:50
How to Deploy a Flask App to a Linux Server
22:12
Просмотров 168 тыс.
How to Deploy a Flask App to Linux (Apache and WSGI)
11:21