Skip to content

SarahRogue81/Flaskr

Repository files navigation

Flaskr

Inspired by Flask's amazing Tutorial.

Changes

  1. Used W3.CSS for basic UI and ability to change colour themes
  2. Used layout UI from What's the Scoop™
  3. Markdown - type Markdown text into the textarea and the blog post displays as HTML
  4. Added The MIT License to the main project so that it's the same license as Flask
  5. Added more config variables (with sane defaults) to the flasker/__init__.py file
  6. Changed font to Raleway for a more professional look
  7. Added permalink (blog detail) for each blog post on the main index page
  8. Added pagination with one blog post showing on the index page which also works properly with the permalinked posts
  9. Added footer displaying copyright, Creative Commons license line, and Powered By line pointing to the inspiration for the blog layout
  10. Added full Font Awesome Free Version 7.0.0 support

Dynamic Blog

To make the Flaskr blog server dynamic, the following variables are set, by default and can be overridden in the instance/config.py file:

  • ALLOW_REGISTRATION – enables/disables user registration
    • default: True
  • BLOG_LICENSE – the name of the Creative Commons license for your blog
    • default: Creative Commons Attribution-NoDerivatives 4.0 International License
  • BLOG_LICENSE_URL – the URL to the License Deed
  • BLOG_OWNER – you or the owner of the blog
    • default: Pallets
  • BLOG_TITLE – the title of your blog
    • default: Flaskr
  • SECRET_KEY – The Flask secret key which should be changed for production, see the Tutorial for further instructions
    • default: dev
  • SHOW_LOGIN – enable/disable the Login button in the navbar
    • default: True
  • W3_CSS_COLOUR_THEME – the W3.CSS Colour Template that you want to use

Installation

Fortunately, installation is very simple.

Get the code from GitHub:

    git clone [email protected]:SarahRogue81/Flaskr.git Flaskr

Setup the Python environment:

    cd Flaskr

    python -m venv .venv

    source .venv/bin/activate

    pip install --upgrade pip

    pip install flask markdown

Initialize the database:

    flask init-db

Configure the blog:

    vi instance/config.py

Run the blog on a dev server:

    flask run --debug

For information on running on a production server, please consult the Deploy to Production section of the Flaskr Tutorial.

Online Dev and Hosting environments

There are many to choose from but Flaskr has been setup to be developed and deployed to Replit as well as PythonAnywhere.

There's nothing that needs be changed to get this to work on either. The uv.log and .replit files are for Replit and the flask_app.py file is for PythonAnywhere. Again, this is all setup for you.

Also, GitHub Codespaces is pretty good to develop on as well. It's like an online VS Code editor. And with their CI/CD cycle, you can't go wrong for any project.

Offline Development

You can't go wrong with vi. It's the only editor that's 100% guaranteed to be there when you SSH into a server, unlike atom. Yes, there's a steep learning curve but at least learn enough for basic editing.

One of my favorites is Zed. It's super light weight and works on any platform.

And, of course, VS Code works as well. It's big plus is the use of Copilot, which is also on GitHub.

While there are others, my all time favorite Python IDE is PyCharm. Its AI doesn't get in the way and it's easy to use.

Security

With the ALLOW_REGISTRATION and SHOW_LOGIN variables in the instance/config.py file, it's really easy to lock down this version of Flaskr.

Once registration is not allowed, the following non-Flask commands can be used to manage users:

  • adduser.py – to add a new user
  • usermod.py – to modify an existing user
  • userdel.py – to remove an existing user

And, for passwords, they are auto-generated with a length of 42 characters consisting of upper & lower case characters, numbers, and symbols.

Just copy the generated password into your Password Manager and you're good to go.

If you can't run those commands in production, have a sane instance/flaskr.sqlite database file ready and deploy it along with the WHL file. No need to flask init-db.

About

Simple blog based off of the Flask tutorial

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published