Saturday, June 11, 2016

Python Flask Tutotials For Beginners Lesson 2 - Flask Hello World and Route Debug Change Port

Hello My dear friends in previous tutorial we have discuss how to setup all the requirements that we need to create video upload web api.so in this tutorial we are going to learn few things.

if images are not clear please click on image to zoom

  • Run Flask Hello world application
  •  
  • Add Debug mod to Flask application
  •  
  • Change Flask Route
  •  
  • Change Host and Port

 Run Flask Hello world application


first open pycharm and goto File and new project then select flask from the menu and give a name and folder to save file.
 

then it will automatically created the hello world program for you


then right click and select run.or you can use alt+shift+f10

then it will give massage it will run on 127.0.0.1:5000

this is run on local host port 5000


so lets type 127.0.0.1:5000 in web browser.

it give a result like this


so you get hello world in Flask.

ok now take a look at the code

from flask import Flask

app = Flask(__name__)



@app.route('/')
def hello_world():
    return 'Hello World!'


if __name__ == '__main__':
    app.run()
  

from flask import Flask

this means we get only Flask module from flask package.
otherwise we can import Flask it will import the all the modules inside the flask package.

app = Flask(__name__)
this means this python program run as flask app named app you can use app or application or whatever name you like

@app.route('/')
This is route this point the function to return value .this is root value that means

if you type 127.0.0.1:5000 this will return Hello World as return

def hello_world():
    return 'Hello World!' 
this is python function

you have to careful to maintain intendant otherwise it will not execute.maintain the suitable spaces.

if __name__ == '__main__':
    app.run()

this means run the main function

Add Debug mod to Flask

when you add debug mod you can run application continuously when the code is changed. 

app.debug=True



Change Host and Port in Python Flask

you can change change host and port in a Flask app using 
host='your IP or host name',port=port number
if __name__ == '__main__':
    app.run(host='127.10.20.30',port=8080) 


Change Route in Flask


route is the pointing point to the python flask function.when you route it will point the relevant function and it will return the output of the function.

@app.route('/')

now we create new function called sayhi().to print hello sameera 

@app.route('/sayhi')
def say_hi():
    return 'welcome sameera ! :) '


 so we are going through the 127.10.20.30:5000/sayhi

this will give the output welcome sameera ! :) in web browser



Hope you enjoy tutorial.see you in next lesson

if you like this tutorial please share in facebook,google+ twitter .If you have any question please leave a comment




Python Flask Tutotials For Beginners Lesson 1 - install and set up Python Flask

Lesson 1 - install and set up Python Flask

Howdy folks after long time .i decided to start new tutorial series about, python Flask framework.in this tutorial series I'm going to teach you ,how to create video hosting flask web server with mango db ,Dockers ,apache reverse proxy and nginx reverse proxy.i hope you will learn a lot.OK lets start to work

things we needed
  • ubuntu
  • pycharm as development IDE
  • python 2.7 (im using python 2.7 version)Ubuntu have built-in python
  • Dockers
  • Apache2 or nginx im going to teach you both
  • Mongo DB
  • Open SSL for convert http to https
im going though all the lesson from very first beginning.

ok lets setup pycharm as our development IDE


Install pycharm

 go to jetbrains pycharm website https://www.jetbrains.com/pycharm/download/#section=linux and download professional or community version.

then extract it to anywhere you like then you can run PyCharm using bash pycharm.sh command to to do this you need to open extracted pycharm folder using terminal.you can use cd command to change the directory and go to pycharm folder then it will start the pycharm.


How to add Pycharm to Ubuntu Laucher


when you open pycharm. Icon is appear on ubuntu Launcher then right click on that icon and click lock to launcher.
and also goto Tools -->Create Desktop Entity 


How to install PIP in ubuntu


sudo apt-get update

sudo apt-get -y install python-pip

this will install pip for you.pip help you to install python modules easy.


How to install Docker in Ubuntu


sudo apt-get update

sudo apt-get install docker-engine

then start the docker daemon using

sudo service docker start

How to install Apache2 on Ubuntu

 Apache2 is the webserver and also apache2 can work as reverse proxy.i will discuss this later.

sudo apt-get update 

sudo apt-get install apache2 apache2-doc apache2-utils


How to install Nginx on Ubuntu

Nginx also web server like apache2.but nginx is light weight rather than apache2 .Nginx require low server requirement.and also memory consumption also lower than apache2.and also nginx can serve as webserver.reverse proxy and load balancer. 

sudo apt-get update

sudo apt-get install nginx


How to install Flask on ubuntu

now you have installed PIP in your ubuntu machine.so we need to install Python Flask on your Desktop so we use pip to install Flask for you.

open terminal and type

 

How To install Python Flask on ubuntu


pip install flask

flask is the micro framework.you can do anything using flask.it is lightweight.it include the core of the framework.

 

How to install Mongodb on Ubuntu

 

sudo apt-get update

sudo apt-get install -y mongodb-org



How to install Pymongo on ubuntu


now we need pymongo driver.to communicate flask app with mongo db

python -m pip install pymongo

ok now we are setup and install althe things we needed .so lets gets started.
see you in next tutorial

How to run your first flask application.

If you like this tutorial Please Share and leave a comment below 




Wednesday, December 30, 2015

Google Search Library For Python Xgoogle

Google Search Module For Python 2.7

It is difficult to find good google search module for python but 
xgoogle is a good package.In this video  I'm demonstrating how to Use xgoogle in ubuntu




how to install IntelliJ IDEA on Ubuntu computer

In this tutorial im going to teach you how to install intelliJ IDEA for java development in Ubuntu Desktop
codes i used
sudo chmod 777 -R idea.sh

./idea

cd for change directory
ls for list of folders and files in current directory
cd.. fo go back step from folder architechture





ONLINECLASSES No19 How to add Android Studio to Ubuntu quick Launcher

ONLINECLASSES No19

Android studio to Ubuntu Launcher

In this video tutorial, I'm going to demonstrate how to add android studio to ubuntu quick launcher to start Android studio in one click



ONLINECLASSES No18 How to download file super fast in ubuntu

ONLINECLASSES No18 

Download files using Axel in Ubuntu


First you have to copy your download link and then open terminal using alt+cntl+T then type and past download link

axel "your download link"
press enter this will download your file with single connection this will be slower
you can use more connection to the server use -n for multiple connections

axel -n32 "your download link"

this will download your file more faster.but what about we give some pretty to this

axel -n32 -a "your download link"

this will prettify the download and hope you learn to download with axel 
thank you for watching

ONLINECLASSES No17 How to install Axel in Ubuntu.Download Accelerator For Linux

ONLINECLASSES No17 Download Accelerator For Linux

you can download files super fast using Axel.axel is download accelerator develop for ubuntu.it have multi-threaded function for download.

sudo apt-get install axel




Sunday, December 27, 2015

ONLINECLASSES No16 How to install Android Studio in Ubuntu/Linux lesson 2

ONLINECLASSES No16 How to install Android Studio in Ubuntu/Linux lesson 2

In this tutorial im going to Demonstrate how to install android studio in ubuntu linux computer
ok here is the summarized steps
1.download Android studio suitable for ubuntu
2.Extract the archive and copy.create folder in home directory and renaim it as Application and past here.
3Open terminal altr+cntl+T
4using cd and you can change directory using cd command and go to your android studio file folder in this case i copied to Application
5.using cd command access to android studio folder and there is bin folder again access bin folder using cd command
cd Application
you can view folders using ls command
cd bin
6.there is file named as studio.sh
7.type sudo chmod 777 +R studio.sh for give permission
8.then we have to run the file for that type .studio.sh
9.now it will open android studio

for more detail you can watch my video

if you have any question please leave comment below.share commnts and subscribe for more cool videos



ONLINECLASSES No15 How to install Java in Ubuntu 14.04

ONLINECLASSES No15 How to install Java in Ubuntu 14.04

Hello and welcome to my blog
Today I’m going to show you how to install java in your Ubuntu desktop and set up .then you can easily install any IDE like pycharm, netbeans, InteliJ IDEA or android studio that will depend on java.
I hope to start new tutorial series on developing android application with Ubuntu so stay tuned. Please leave comments and if you think this will helpful so you can share this tutorials with your friends too
Have a good day

Sameera Dissanayaka




Friday, September 11, 2015

ONLINECLASSES No14 How to get super user permission on Ubuntu(How to get root access in Koding server)

ONLINECLASSES No14 root access in ubuntu

in this tutorial im going to teach you how to get super user permission on Koding server
type sudo passwd
 then enter new password
and retype again
then you can gain super user using su command



ONLINECLASSES No13 How to install scapy on python 3

ONLINECLASSES No13 pip3 install scapy-python3

in this video tutorial. im going to show you how to install scapy on python 3 easily
 hope you enjoy my tutorial
if you learn something from this
please share and like


Friday, September 4, 2015

ONLINECLASSES No12 How to install Node js on windows computer

ONLINECLASSES No12  How to install Node js on windows computer

hello viewers in this video tutorial i'm demonstrate how to install Node Js on windows computer .and check it is correctly installed or not

ONLINECLASSES No11 How to install Beautiful Soup Python HTML parser and LXML Easy way

ONLINECLASSES No11 How to install Beautiful Soup Python HTML parser and LXML Easy way 

hello i have created tutorial to how to install Beautifulsoup HTML parser and LXML in easy step.
Beautifulsoup is the html parser that help you to get website content to your python projects.
here is the video tutorial
enjoy

Monday, August 24, 2015

ONLINECLASSES No9 how to install NLTK using pip install nltk

ONLINECLASSES No10

hello there
in this tutorial im going to show you some easy way to install nltk framework for natural language processing .nltk is the framework that you can easily analyse the natural language to computer understandable language.im not going to talk about NLP here because its huge area.i like to share my knowledge with you i'm hoping to provide simple NLP tutorial lessons in future.
wel lets go to work


how to install NLTK in python 3.4 in windows computer


first you need to setup pip(python installer package).here is the my previous tutorial about install pip module in windows computer
http://hackkat.blogspot.com/2015/08/how-to-install-pippython-installer.html

now its easy open command prompt in administrative mode

click on image to better view





then type pip install nltk and then press enter



that's is now its started to download and it will automatically install NLTK module in to your computer
you can verify if it is installed or not by typing import nltk in python IDE if its shows no errors you have successfully install NLTK
Have a good day
please if you like this post share on facebook twitter,if you have any question please leave a comment below
#installnltkusingpip,#pipinstallnltk,#nltk,#nlppython


ONLINECLASSES No 8How to install pip(python installer Package)

ONLINECLASSES No8 pip install

hello there.how are you hope you are fine in today lesson i'm going to teach a simple lesson .its about
pip install.in python 2.7 version there is no inbuilt pip so we need to configure the pip in to our computer but in python 3.x versions its contain the pip module by default. That's means you don't need to install pip separately.

usefulness of pip

when you are setup pip you can easily install python modules in few types

ok then lets go to work

first you need to download python latest version from this link https://www.python.org/downloads/

after that install python 
then you have done
 but when you are considering about the pip .there is still problem because our computer doesn't know where is the pip is exact location of pip so we have to go to the python folder and script folder see image below




then copy link address

in my computer its c://python34/script


then you have to go to system variables for that right click on my computer go to properties and then go to advance settings then environmental variables






then you can see the variable name path then select it and click edit then you get new window and be careful not to delete any thing in here at the end of the line just put ; mark and then past the link that you copied here is the screenshot of mine you can easily understand



then click ok  and you are ready to go
 then open command prompt and type pip if all the things are OK then you can get all the modules you can use with pip

thanks for watching if you are like my tutorial please share in Facebook,twitter and if you have any question about my tutorial please leave a comment
have a good day
by
Sameera Dissanayaka

#pipinstall,#howtoinstallpipinpython3.4,#pythonforbeginners,#hackkatpython