Showing posts with label Web2py. Show all posts
Showing posts with label Web2py. Show all posts

Saturday, February 6, 2016

Getting started with web2py using pythonanywhere web hosting service (cloud)


This post tells you, how to deploy and execute python code written using web2py framework in
pythonanywhere web hosting service kind of cloud for python.
First write any sample code using web2py framework. Sample codes you can check my previous posts like getting started with web2py , blog app using web2py

Once you have completed the simple project, then we need to deploy the same using the cloud.
Web2py can be deployed any web hosting services, now we will look how we can deploy using https://www.pythonanywhere.com/




Click on Signup here! (if you are not sign up yet)




Click on Create a Beginner account and provide the required details, it is enough to post any details in internet.




After successful sign up and Login then, you can redirected to pythonanywhere


Click on DashBoard Then Click on Web




Now we need to create new web app (Click on Add anew web app).




Pythonanywhere will support so many python frameworks, Select the web2py , since we are implementing application using web2py.





Provide the password , which is required to access the application. It will created directory (/home/siva82k/web2py/) with my username.
Click on Next, which will create url for you


Now you can check your application through internet, usually welcome application will be copied to your account.
My case my url will be http://siva82k.pythonanywhere.com, if you try to click on this you can redirected to your application.




Now it’s time to deploy our existing code into pythonanywhere site. First go to our application, where we have written our code, click on pack all as shown in below image.




Then save the code in local system.Once it is completed then go to your pythonanywhere site.
Click on Administrative Interface, and the provide the password, which you have given while creating web2py account.



After successful Login, it will redirected to below page



We need to upload the file into python anywhere site . Provide the details under upload and install packed application
I am providing Application name as sivaweb2py
Upload a package from your local system, Earlier where you have downloaded.
Then click on install, our application got installed on pythonanywhere machine.
Now what ever we did in local host machine same thing available in pythonanywhere internet.
You can check my previous posts related to web2py examples.
Earlier we checked Role based access, same thing we will check in pythonanywhere
Click on https://siva82k.pythonanywhere.com/sivaweb2py/blog/view

It will ask the username and password , in my case I have provided user only (siva82k@gmail.com), have access to post the blog.
https://siva82k.pythonanywhere.com/sivaweb2py/blog/post



If we provide correct user name and password, it will take us to post the blog.



If we provide other details, other than post access then it will say you are not authorized.



One more example which we have worked earlier, basics to add the 2 numbers
https://siva82k.pythonanywhere.com/sivaweb2py/basics/request_args/10/20



We can test whatever we did in our previous examples in local system, same thing available in internet.
This is how we can deploy our web2py code using pythonanywhere.
Thanks for viewing this post








Sunday, January 10, 2016

Getting started with web2py framework



    Full Stack web development with Python (Web2Py)
    How to download and install web2py
1.  Go  to http://web2py.com/
2.   Down load latest version http://web2py.com/init/default/download
     Unzip the downloaded file
     CliCk on the Web2py.exe file to it will open the window like below





           Provide the password(any password) and start the server
           Server has been started. Now we need to create a application using web2py framework.
           http://localhost:8000

                                                

         Click on the Admin,  which is there on the right side in the page. And provide the password which      we have given while starting the server





                After Successful Login,  page will be open like below.

               Create a new application using this framework- > New simple application –
       Application Name - ex: sivaweb2py
              Click on the create button. Now we have created application successfully.
               Need to run the application
               http://localhost:8000/sivaweb2py
               


              Now we need to write sample code in this application. So we need to understand basics of  the
       framework
               Need to edit the application


      This framework will follow MVC architecture
          Model- Contains db details
         Controller – Method and logic details
         Views – Html input/output to the user

Now we need to create one controller and respective views
Click on the Create button under Controller Section
I have given controller name as basics – basics.py will be created under controller

       Now edit the controller – Click on the basics.py
     def helloworld():
     msg= "Hello welcome to basics controller!"
     return locals()


 In the above code helloworld is method name . Copy the code and paste the same in your file.
  Save the file and go to back – by click on the back buton
  Now we need to create a  view- under Views section
  View name should be as method name  ex: basics/helloworld

   {{extend 'layout.html'}}
    This is our first web page
   {{ =msg}}

Writing first web2py is very easy


                          

        

                               






AddToAny

Contact Form

Name

Email *

Message *