Code Monkey home page Code Monkey logo

flask-blog's Introduction

Responsive-Blog-Template

A simple blog written with Flask framework and MySQL database.

Screenshots

Home page

home_screenshot

Articles dashboard

dashboard_screenshot

Features

The following features are included in this project:

  • user authentication
  • user registration
  • create, edit and delete articles
  • admin dashboard
  • tags
  • fully responsive, easily customizable design
  • user friendly, easy to use interface

How to setup the database?

The application can't function without a MySQL database. There are multiple ways to setup the database. Easiest way to locally setup a MySQL database is using docker.

First, you need make sure you have docker installed. If you don't, you can install it using the following command if you are on Debian-based Linux distribution:

$ sudo apt-get update
$ sudo apt-get install docker.io

Then, you need to create a docker container for your database:

$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret_pass mysql

The container will be running on port 3306. The secret_pass is the password for the root user of the database. You can use any password you want.

You can find the container id by running the following command:

$ docker ps

To ssh into the container, you can use the following command:

$ docker exec -it <container_id> /bin/bash
$ mysql -u root -psecret_pass

You can now create the database:

$ CREATE DATABASE flask_db;

The last thing is two create expected tables. The app works with two tables:

- `articles`
- `users`

Table articles has the following columns:

- `id`: primary key
- `title`: string
- `body`: text
- `author`: string
- `date`: datetime
- `image`: string

Use the following command to create the table:

CREATE TABLE IF NOT EXISTS articles (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    body LONGTEXT NOT NULL,
    author VARCHAR(255) NOT NULL,
    date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    image VARCHAR(255) default '/static/images/default.jpg'
);

Table users has the following columns:

- `id`: primary key
- `name`: string
- `email`: string
- `username`: string
- `password`: string
CREATE TABLE IF NOT EXISTS users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20) NOT NULL,
    email VARCHAR(40) NOT NULL,
    username VARCHAR(20) NOT NULL,
    password VARCHAR(255) NOT NULL
);

Installation

You can run the application without the database, but you will not be able to create or edit articles. It is recommended to first setup the database.

Using virtual env:

$ git clone https://github.com/djeada/Responsive-Blog-Template.git
$ cd Responsive-Blog-Template
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt
$ python3 src/app.py

If you are using a Debian-based system and encountered toruble while installing the mysql requirements, try the following first:

$ apt install python3-dev default-libmysqlclient-dev build-essential

Using docker:

$ docker run -d -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock -v /home/user/Responsive-Blog-Template:/app djeada/flask-blog

How to use?

If the application is running on localhost, you can access it using the following url:

http://localhost:5000/

To register a new user, you can use the following url:

http://localhost:5000/register

To login, you can use the following url:

http://localhost:5000/login

To create, edit or delete articles, you need to login first. Then, you can use the following url:

http://localhost:5000/dashboard

TODO

  • Add exception handling to all python files that are interacting with the DB.
  • Introduce variables to CSS.
  • Test on different devices.
  • Make full project specification.
  • Enable storing of images in the database.
  • Add tags to the database.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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.