Flask with static html files
Python hosting: Host, run, and code Python in the cloud!
You can use the Flask framework and use static files together.
Flask will give you URL routing, many features and all the Python benefits.
You may want an application that is partly dynamic and partly static. Or you may simply want to browse with URL routing. In this article we will teach you how to load static HTML files with Flask.
Related course
Python Flask: Make Web Apps with Python
from flask import Flask, render_template |
This application initializes a Flask app with the method:
|
The app creates an URL route for any possible page and links that to static html files with:
|
</string:page_name>
Create a directory /templates/ and add the file hello.html:
|
Start the server with:
$ python app.py |
Then any .html file is accesible using URL routing.
For example the static file hello.html can be accessed using http://127.0.0.1:5000/hello. You can store any css file in the /static/ directory.
Leave a Reply:
I'm using Qpithon3 on Android.
When i started app, console returns:
SyntaxError: invalid character in identifier
1|u0_a97@osprey_u2:/ $
What is wrong?
.
not sure if Flask works on Android. Do you have the modules Flask and render_template installed?
It works, but you are right. I'm trying to code on mobile with Qpithon3. It has Python 3.2.2 core. Flask does not support exactly this relise.
Thank you. What a sorrow. Now I'm trying Bottle. Per *censored* ad astra ).
In two places on this page, there appears the string "". I think this is misplaced HTML closing tag.
In this case all the urls are dynamic. This is a quick example that lets you get any type of file. In a real world app, you would not make all routes dynamic but inside a folder like static/page_name