$ curl localhost:5000
Hello Flask!
$
We’ll build a URL shortener service (like bit.ly)
Create a web server that return "Hello Flask!" when you issue a GET request.
$ curl localhost:5000
Hello Flask!
$
pip install Flask
Have the web server return a page for submitting URL.
templates
directory
Serve static files from static
directory.
style.css
there and make the header blue.
Have a click on the [+] button submit the form.
We’ll use SQLAlchemy and flask-sqlalchemy extension.
Schema:
short
: short url, text, primary key
long
: long (original) url, text
hits
: number of hits, integer
Add a line to the output HTML showing how many links we’ve shortened so far.
pip install flask-sqlalchemy
count
example
Handle the form data and store and short URL in the database.
For short URLs, we store a global counter and base62 to encode it as the short URL.
Add a list of the 10 most populate links at the bottom of the page. Populate the list by AJAX call the get JSON object back.