Python Web Development 1

Source: Internet
Author: User

The first Python web development.
Related to: Flask architecture, MySQL database.
Function: Diary. Development.
Flask architecture, MySQL database.
Function: Diary.

1  fromFlaskImportflask,render_template2  fromFlaskImportRequest3 ImportPymysql4 5 6 7 #Example flask This class8App = Flask (__name__)9 Ten # One@app. Route ('/') A defIndex (): -     returnRender_template ('index.html') -  the@app. Route ('/creat') - defcreatdiary (): -     returnRender_template ('creat.html') -  +  -  +conn =Pymysql.connect ( Ahost='127.0.0.1', atUser='Root', -password='USBW', -port=3307, -Database='Diary', -charset='UTF8' -     ) incursor = Conn.cursor (cursor=pymysql.cursors.DictCursor) -  to@app. Route ('/upload', methods=['GET','POST'])#The only way to ask for it is get + defupload (): -Date=request.form.get ('Date') theKey=request.form.get ('Key') *Title=request.form.get ('title') $Content=request.form.get ('content')Panax Notoginseng     #files=request.files.get (' file ') -     Print(date,key,title,content) theSql="INSERT into ' Day ' (' Date ', ' class ', ' title ', ' content ') VALUES (%s,%s,%s,%s)" + Cursor.execute (sql,[date,key,title,content]) A Conn.commit () the    #cursor.close () + conn.close () -     return 'Submit Success! ' $  $@app. Route ('/diarylist') - defdiarylist (): -     returnRender_template ('diarylist.html') the  - if __name__=='__main__':WuyiApp.run ()

Python Web Development 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.