Showing posts with label blog app using web2py. Show all posts
Showing posts with label blog app using web2py. Show all posts

Saturday, January 23, 2016

Create a blog app using Web2py

1. Start web2py
2. Usually blog will have post and view the post details
3. Validations required to validate the post
4. Database design to store title, content, image category , blog posted date etc..
First we need to create model

5. Edit the file
6.End of the file add the below code, to create a table 'blog' along with columns


We need to use validators inside model, more validators look inside

                 Field('blog_title', requires=IS_NOT_EMPTY()),
                 Field('blog_details', type='text'),
                 Field('blog_date_posted', type='date',requires=IS_DATE()))


7. Need to add validation for table details

8.Now we need to create a controller, to post the blog app
9.Create controller name called blog under controller section
11. Add two methods one is called post and one is view

def post():
       form =SQLFORM(
       return locals()
      def view():
      rows = db(
      return locals()


12.Now we need to create views as blog/post and blog/view
13.Edit the blog/
{{extend 'layout.html'}}

post a blog as you like


14.If you submit without entering any values, then it will show the validation errors

Provide the details as required and submit the same. You can see the success message.

Need to know more about SQLFORMS and validators
Now we need to update the blog

Edit the and add the below code for update method

def update():
    record = or redirect (URL(post))
    form = SQLFORM(,record)
    if form.process().accepted:
        response.flash = T('Record Updated')
        response.flash=T('Please complete the form')
    return locals()

Create update view under views section
{{extend 'layout.html'}}

Update the form


Click on the below link to update the record or provide number after update method which ever record want to update

Now we need to create the view page

{{extend 'layout.html'}}

View the blog

{{ for x in rows:}}
blog image



blog Details:{{=x.blog_details}}

blog posted:{{=x.blog_date_posted}}

{{ pass }}

After adding the above code in, if we check the result using below url

This is how we can create a blog app using web2py.


Contact Form


Email *

Message *