Python server with Flask

With Flask and SQLAlchemy I talked about in the last post, I was able to implement a python server. It is able to show a list of restaurants in the main page. Clicking on restaurant names show their menu, and each menu item can be edited or deleted. Users can also create new menu items. The database uses SQLAlchemy, and url resolving and HTTP requests handling use Flask, a microframework that makes implementations of web servers very easy.

The link to the project on GitHub is here.

With flask, resolving url addresses is simply app.route('format'), and under this line declare the method for this address. Here is an example:

This means whenever the address fits the format host/restaurants/int, the method restaurantMenu will be executed. restaurant_id is a variable extracted from the url and passed in the method as a parameter. Whatever this method returns shows up on the webpage. In this case, the method is returning the result of render_templaterender_template is a method in Flask that looks for the template specified in the first parameter in /templates and pass in necessary variables. menu.html looks like this:Screen Shot 2016-01-13 at 9.40.55 AM

items is the variable passed in this template. Here html execution arguments are used.

url_for is another tool used in this project. It is also included in Flask. The first parameter is the handler method of the product url, and other parameters are variables passed.

The next step is for methods to handle both GET and POST HTTP methods. Here’s how to do it:

methods need to be put in @app.route. Of course, request class also needs to be imported from Flask. Handling different kinds of methods is virtually the same as handling one. It’s only one if statement away.

Finally, for the server to repond to requests with JSON object, objects in the database need to have a function that returns all of their information.

In object class of the database setup python file:

And then use jsonify class provided by Flask to return json:
return jsonify(MenuItem = menuItem.serialize)
The json can then be used by any kind of application!

As a next step of this project, I plan to implement a server that works with iOS applications. I may need to write a framework for Swift to talk with my server. This means a lot of work, but it has great potential!

I’ll just forget about the fact that I have a midterm 30 minutes later and one more tomorrow.

36 thoughts on “Python server with Flask”

  1. OK I seriously need to resolve that http error when I upload pictures. I find that the files appear in wp-content but they do not show up in WordPress editor. It may be some owner or permission issue.

  2. Dear you are comprehensive in your thoughts. I have made something for guys to find their life partner. Please check my blog and share with people who need this guide.

  3. I spent four years trying EVERYTHING in Online Dating, and through a huge amount of trial and error, I produced a system that I will share for you. This book will take you, step by step, through everything you need to know to double, triple or even quadruple the number of women you meet online.

  4. Venus Viva™對所有皮膚類型都是安全的,並使用革命性的Nano Fractional Radio Frequency™(納米點陣射頻™)和Smart Scan™(智能掃描™)技術,通過選擇性真皮加熱,從而提供優異的治療效果。使用Nano Fractional RF™將能量透過表皮傳遞至真皮,從而產生熱量,並啟動膚膚的生理機制,重建膠原蛋白及刺激纖維母細胞,最終刺激導致組織重塑。功效:✔改善膚質✔肌膚緊緻✔減淡妊娠紋✔痤瘡及暗瘡疤痕✔減淡細紋及皺紋✔面部肌膚賦活再生 適合面部及頸部

  5. Echo Touch魔法保濕凝膠腳膜 韓國銷量已衝破一百萬對!!!!可以重覆用N次,無需過水既保濕凝膠襪子/手套Echo Touch魔法保濕凝膠手膜/腳膜,係韓國已經熱賣出一百萬對仲有韓國人氣節目Get it Beauty 都有介紹過,用完之後即時令手腳回復嫩滑,而且可以重複使用200-300次,99蚊用足成年,又抵用又環保。打開個包裝已經聞到好香,手套/襪子入面有一層gel,gel 既成份有維他命E、橄欖油,荷荷巴精油、綠

  6. 大熱刺繡 look! Marie Claire (HK) Edition Embroidery 元素從來無分季度,不但由秋冬紅到春夏,還能夠每年也不斷重複大熱!來到2018春夏,刺繡當然會出現於雪紡薄紗等質料上,再加入珠片元素即時令設計既復古又仙氣! 你也想入手一兩件刺繡

  7. Sculptra 含有由含有源於植物果酸的 PLLA 聚左乳酸(poly-L-lactic acid),它能促進天然膠原蛋白大量增生,令容顏重現年輕,一個療程的效果能持續逾2年。Sculptra 乃全球唯一獲美國食物及藥物管理局(美國FDA)認可的PLLA聚左乳酸美容品牌。Sculptra 塑然雅會被人體自然分解吸收,同時促進天然膠原蛋白再生1。療程效果可以漸進地給你更富清新朝氣的容頻,效果自然,更不會影響面部表情。SCULPTRA 塑然雅 Sculptra 由含有源於植物果酸的PLLA聚左乳酸(poly-L-lactic acid),它可以被新陳代謝成二氧化碳及水,最終自體內排出。PLLA聚左乳酸早已被廣泛應用於醫療用品超過30年,自2009年起 Sculptra 及全球唯一獲美國FDA認可的PLLA聚左乳酸美容醫學品牌。Sculptra ® 塑然雅能促進天然膠原蛋白大量增生1,改善皺紋,令容顏重現年輕。全球唯一獲美國FDA認可PLLA聚左乳酸。臨床研究證實於3個月間,肌膚的膠原蛋白密度 顯著增加67%2。療程效果能持續愈2年3。主要成份PLLA聚左乳酸源於植物果酸,醫學界廣泛使用超過30年。

  8. Have you ever thought about adding a little bit more than just your articles?I mean, what you say is important and everything.However just imagine if you added some great visuals or video clips to give your posts more,“pop”! Your content is excellent but with images and video clips,this website could undeniably be one of the best in its field.Good blog!

  9. Wow that was strange. I just wrote an really long comment butafter I clicked submit my comment didn’t showup. Grrrr… well I’m not writing all that over again. Anyhow, just wantedto say wonderful blog!

  10. Air Jordan 12 Gym Redhttp://www.jordan12gymred.us.com/
    nike factory outlet store onlinehttp://www.nikefactoryoutletstoreonline.com/
    Nike Outlet satorehttp://www.nikefactoryoutletstoreonline.us/
    Nike Outlethttp://www.nikestores.us.com/
    jordan 33http://www.jordan33.us/
    Yeezy Shoeshttp://www.cheapjerseysfromchina.us/
    custom nfl jerseyshttp://www.customnfljerseys.us/
    jordan 11 concord 2018http://www.jordan11concord.us.com/
    Jordan 12 Gym Redhttp://www.jordan12gymred.us/
    Jordan 12 Gym Redhttp://www.redjordan12.us/
    Yeezy Shoeshttp://www.yeezy.com.co/
    Yeezy Shoeshttp://www.yeezys.us.com/
    Yeezy Supplyhttp://www.yeezysupply.us.com/
    Yeezy Sneakershttp://www.yeezy-shoes.us.com/
    Yeezy Boosthttp://www.yeezy-boost350.com/
    Yeezy Boost 350 V2http://www.yeezyboost350.us.com/
    Yeezy Boost 350 V2 Blue Tinthttp://www.yeezybluetint.com/
    Yeezy 500 Utility Blackhttp://www.yeezy500utilityblack.com/
    Yeezy 500http://www.yeezy500utilityblack.us/
    Nike VaporMaxhttp://www.vapor-max.org.uk/
    Salomonhttp://www.salomon-shoes.org.uk/
    Salomonhttp://www.salomons.me.uk/
    Salomon Speedcross 4http://www.salomonspeedcross4.org.uk/
    Off White Air Jordan 1http://www.offwhitejordan1.com/
    Nike VaporMaxhttp://www.nikevapormax.org.uk/
    Nike React Element 87http://www.nikereactelement87.us.com/
    React Element 87http://www.nikereactelement87.us/
    Nike Plushttp://www.nikeplus.us/
    Nike Outlethttp://www.nike–outlet.us/
    Nike Outlet Store Online Shoppinghttp://www.nikeoutletstoreonlineshopping.us/
    Nike Outlethttp://www.nikeoutletonlineshopping.us/
    Cheap Nike NBA Jerseyshttp://www.nikenbajerseys.us/
    Air Max 97http://www.nikeairmax.us/
    Air Max 2017http://www.max2017.us/
    Jordan Shoes 2018http://www.jordan-com.com/
    Jordan 11 Concordhttp://www.jordan11-concord.com/
    Kanye West Yeezys Boost Shoeshttp://www.cs7boots1.com/
    Cheap NBA Jerseys From Chinahttp://www.cheapnba-jerseys.us/
    Birkenstock Sandalshttp://www.birkenstocksandalsuk.me.uk/
    NBA Jerseyshttp://www.basketball-jersey.us/
    Balenciaga UKhttp://www.balenciaga.me.uk/
    Balenciagahttp://www.balenciagauk.org.uk/
    Balenciagahttp://www.balenciagatriples.org.uk/
    Balenciaga UKhttp://www.birkenstocks.me.uk/
    Balenciagahttp://www.balenciagatrainers.org.uk/
    Nike Air Max 270http://www.airmax270.org.uk/
    Adidas Yeezyshttp://www.adidasyeezyshoes.org.uk/
    Adidas Yeezy Shoeshttp://www.adidasyeezyshoes.org.uk/

  11. Air Jordan 12 Gym Red http://www.jordan12gymred.us.com/
    Nike Outlet satore http://www.nikefactoryoutletstoreonline.com/
    Nike Outlet satore http://www.nikefactoryoutletstoreonline.us/
    Nike Store http://www.nikestores.us.com/
    retro jordan 33 http://www.jordan33.us/
    Yeezys http://www.cheapjerseysfromchina.us/
    custom nfl jerseys http://www.customnfljerseys.us/
    jordan 11 concord http://www.jordan11concord.us.com/
    Jordan 12 Gym Red http://www.jordan12gymred.us/
    Jordan 12 Gym Red http://www.redjordan12.us/
    Yeezy Shoes http://www.yeezy.com.co/
    Yeezy http://www.yeezys.us.com/
    Yeezy Supply http://www.yeezysupply.us.com/
    Yeezy Boost 350 http://www.yeezy-shoes.us.com/
    Yeezy Boost http://www.yeezy-boost350.com/
    Yeezy Boost 350 V2 http://www.yeezyboost350.us.com/
    Yeezy Blue Tint http://www.yeezybluetint.com/
    Yeezy 500 Utility Black http://www.yeezy500utilityblack.com/
    Adidas Yeezy 500 http://www.yeezy500utilityblack.us/
    Nike VaporMax http://www.vapor-max.org.uk/
    Salomon UK http://www.salomon-shoes.org.uk/
    Salomon UK http://www.salomons.me.uk/
    Salomon UK http://www.salomonspeedcross4.org.uk/
    Off White Air Jordan 1 http://www.offwhitejordan1.com/
    Nike Air VaporMax http://www.nikevapormax.org.uk/
    React Element 87 http://www.nikereactelement87.us.com/
    Nike Element 87 http://www.nikereactelement87.us/
    Nike Plus http://www.nikeplus.us/
    Nike Outlet Store http://www.nike–outlet.us/
    Nike Outlet http://www.nikeoutletstoreonlineshopping.us/
    Nike Outlet http://www.nikeoutletonlineshopping.us/
    Nike NBA Jerseys http://www.nikenbajerseys.us/
    Air Max 97 http://www.nikeairmax.us/
    Air Max Nike http://www.max2017.us/
    Jordan Shoes 2018 http://www.jordan-com.com/
    Jordan 11 Concord 2018 http://www.jordan11-concord.com/
    Cheap Yeezy Boost http://www.cs7boots1.com/
    Wholesale Cheap NBA Jerseys http://www.cheapnba-jerseys.us/
    Birkenstock Sandals UK http://www.birkenstocksandalsuk.me.uk/
    Basketball Jersey http://www.basketball-jersey.us/
    Balenciaga http://www.balenciaga.me.uk/
    Balenciaga http://www.balenciagauk.org.uk/
    Balenciaga UK http://www.balenciagatriples.org.uk/
    Balenciaga http://www.birkenstocks.me.uk/
    Balenciaga UK http://www.balenciagatrainers.org.uk/
    Nike Air Max 270 http://www.airmax270.org.uk/
    Yeezy http://www.adidasyeezyshoes.org.uk/
    Adidas Yeezy Shoes http://www.adidasyeezyshoes.org.uk/

  12. obviously like your web site however you need to check the spelling on quite a few of your posts. Several of them are rife with spelling problems and I in finding it very bothersome to tell the reality then again I will certainly come again again.

  13. Like all fields, photography, professional photography at this, just isn’t aas easy asonee may think. Flowers can be found iin a range ofcolors, and if you add stems and vines, you can find an incredible custom taytoodesign. Thhe mention of Bro-step and American expansion of the genre iis undeniable here iin the firszt sort context.

  14. The bulbs are specifically designed to retrofit fluorescent fixtures (T8 in particular, not T12), and specify on the box that no ballast removal is required. I have no safety concerns—especially as they’re in the garage and will only ever be on when someone is in the garage.From a comment on Amazon, if you install them in a T12 fixture, the light will shut off (thermal protection mode) when left on for some length of time. However, someone else commented they’re working fine in their T12 fixture.-rob.

Leave a Reply

Your email address will not be published. Required fields are marked *