Code Monkey home page Code Monkey logo

learning-flask's Introduction

learning-flask

First looks into Flask

Start in Develop

FLASK_ENV=development FLASK_APP=src/application.py flask run

Jinja-template

https://overiq.com/flask-101/basics-of-jinja-template-language/

##TODO

Basis

  1. template einbinden
  2. main-styles.css
  3. api: gibt dictionary(json) zurück
  4. template einbinden done
  5. main-styles.css done
  6. api: gibt dictionary(json) zurück done
  7. javascript einbinden, was folgende Feature z.b implementiert:
    1. Button "Hello"
    2. Klick auf "Hello" => javascriot funktion doHello aufrufen und einen Modal (alert) "Hello world" anzeigem

Stufe 2

  1. für dictionary eigenen datei ablegen

Single Page mit css, javascript and template

Neue Template

  1. Ertelle neue Templates static/dogs.html
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Dogs</title>
  </head>
  <body>
    <div>
      <h1>The gallery of dogs</h1>
      <em>This is a Singlepage application using Flask, javascript, html and css</em>
      <hr/>
    </div>
  </body>
</html>

  1. Erstelle neue Funktion und Route in application.py
@app.route("/dogs/")
def dogs_index():
    return render_template('dogs.html')
  1. start Flask:
FLASK_ENV=development FLASK_APP=src/application.py flask run
  1. öffne in Browser http://127.0.0.1:5000/dogs/ first-step

CSS Datei erstellen und einbinden

  1. static/dogs.css
body {
    padding: 24px;
}
em {
  color: #857f7f;
}
  1. dogs.html
...
  <head>
    ...
    <link rel="stylesheet" href="{{ url_for('static', filename='dogs.css') }}">
    ...
  </head>
...  
  1. Browser aktuallisieren css-added

create dependency file

pip freeze > requirements.txt

Auf Heroku hosten

siehe https://stackabuse.com/deploying-a-flask-application-to-heroku/

  1. erstelle neuen Python Daten auf Projekt-Root wsgi.py:
from src.main import *
if __name__ == "__main__":
  app.run()
  1. installiere gunicorn
pip install gunicorn
  1. erstelle requirements.txt
pip freeze > requirements.txt

für Flask benötigte Libraries sieht so aus:

click==8.0.3
Flask==2.0.2
Flask-Cors==3.0.10
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
names==0.3.0
Werkzeug==2.0.2
  1. Erstelle Profile
web: gunicorn wsgi:app

Trick und Tip:

Arbeit mit fremde Bilder: https://www.digitalocean.com/community/tutorials/css-cropping-images-object-fit

learning-flask's People

Contributors

thien-minh-ngo avatar ngtungngo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.