Compare commits
No commits in common. "00f7c1de33f47e70db4ff43c138ba85f07027c3d" and "199d19a7bf99440e7db0d13244dae56fc038fd4e" have entirely different histories.
00f7c1de33
...
199d19a7bf
9 changed files with 15 additions and 74 deletions
|
|
@ -1,3 +0,0 @@
|
||||||
Merge requests and issues are welcome.
|
|
||||||
|
|
||||||
Merge requests must be targeted at issues, with each merge request including a line (or multiple) "Closes #<issue-number>" in it. If a merge request doesn't close an issue, consider raising an issue before submitting the MR.
|
|
||||||
21
README.md
21
README.md
|
|
@ -1,29 +1,16 @@
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
From the root directory, run `pip install -r requirements.txt` to install the package (and all dependencies) in editable mode.
|
From the root directory, run `pip install -r requirements.txt` to install the package (and all dependencies) in editable mode.
|
||||||
Use `gunicorn -w 2 'flaskr:create_app()'` to run app. Increase the number of workers using the `-w` argument if desired. The package will be updated as you edit files.
|
Use `flask --app flaskr run` to run app. The package will be updated as you edit files.
|
||||||
|
|
||||||
## Production
|
## Production
|
||||||
Run `python -m build --wheel` to generate the wheel, and install the wheel (found in `dist/`) in the production environment.
|
Run `python -m build --wheel` to generate the wheel, and install the wheel (found in `dist/`) in the production environment.
|
||||||
Use `gunicorn -w 2 'flaskr:create_app()'` to run app. Increase the number of workers using the `-w` argument if desired. To update package, you will need to install a new wheel.
|
Use `flask --app flaskr run` to run app. To update package, you will need to install a new wheel.
|
||||||
|
|
||||||
## Initializing database
|
## Initializing database
|
||||||
The first time you install the app in each environment, you need to initialize database using `flask --app flaskr init-db`. This only needs to be run once per environment, and **will delete existing database if run again**.
|
The first time you install the app in each environment, you need to initialize database using `flask --app flaskr init-db`. This only needs to be run once per environment, and **will delete existing database if run again**.
|
||||||
|
|
||||||
## Config file
|
## Secret key
|
||||||
|
|
||||||
The config file is located at `<python_environment>/var/flaskr-instance/config.py` in production, and in `instance/` in development. The instance folder is created when the database is initialized.
|
|
||||||
|
|
||||||
### Secret Key
|
|
||||||
Every website with login needs a secret key to hash passwords with.
|
Every website with login needs a secret key to hash passwords with.
|
||||||
The config file must contain a line `SECRET_KEY = '<secret_key>`, which must be randomly generated.
|
`<python_environment>/var/flaskr-instance/config.py` must contain a line `SECRET_KEY = '<secret_key>`, which must be randomly generated.
|
||||||
Suggested way of generating the key is `python -c 'import secrets; print(secrets.token_hex())'`, which returns a hexadecimal string with length 64. You may choose to randomly generate a key using a different method, but ensure that it is resistant to brute-force attacks.
|
Suggested way of generating the key is `python -c 'import secrets; print(secrets.token_hex())'`, which returns a hexadecimal string with length 64. You may choose to randomly generate a key using a different method, but ensure that it is resistant to brute-force attacks.
|
||||||
|
|
||||||
### Registration
|
|
||||||
Since this blog is meant to be updated by a limited number of people, registration is forbidden (403) by default. In addition, registration (/auth/register) and login (/auth/login) URLs are not hyperlinked anywhere. Registration can be opened by including `REGISTER = True`, and is closed by default.
|
|
||||||
|
|
||||||
### Name
|
|
||||||
The default app name is "Flaskr", and it is visible on the header bar as well as the page title. Including a line `NAME = '<name>'` in the config file replaces "Flaskr" with your chosen name.
|
|
||||||
|
|
||||||
### Static folder
|
|
||||||
The default static folder is the one included in the repository. You can use a separate static folder to use your own assets by including a line `STATIC_FOLDER = '<absolute/path/to/folder>'` in the config file.
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
# create and configure the app
|
# create and configure the app
|
||||||
|
|
@ -8,12 +7,6 @@ def create_app(test_config=None):
|
||||||
app.config.from_mapping(
|
app.config.from_mapping(
|
||||||
SECRET_KEY='dev',
|
SECRET_KEY='dev',
|
||||||
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
|
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
|
||||||
REGISTER=False,
|
|
||||||
NAME='Flaskr'
|
|
||||||
)
|
|
||||||
|
|
||||||
app.wsgi_app = ProxyFix(
|
|
||||||
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if test_config is None:
|
if test_config is None:
|
||||||
|
|
@ -23,9 +16,6 @@ def create_app(test_config=None):
|
||||||
# load the test config if passed in
|
# load the test config if passed in
|
||||||
app.config.from_mapping(test_config)
|
app.config.from_mapping(test_config)
|
||||||
|
|
||||||
if app.config.get('STATIC_FOLDER') is not None:
|
|
||||||
app.static_folder = app.config.get('STATIC_FOLDER')
|
|
||||||
|
|
||||||
# ensure the instance folder exists
|
# ensure the instance folder exists
|
||||||
try:
|
try:
|
||||||
os.makedirs(app.instance_path)
|
os.makedirs(app.instance_path)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint, flash, g, redirect, render_template, request, session, url_for, current_app, abort
|
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||||
)
|
)
|
||||||
from werkzeug.security import check_password_hash, generate_password_hash
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
|
||||||
|
|
@ -11,8 +11,6 @@ bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
|
||||||
@bp.route('/register', methods=('GET', 'POST'))
|
@bp.route('/register', methods=('GET', 'POST'))
|
||||||
def register():
|
def register():
|
||||||
if not current_app.config['REGISTER']:
|
|
||||||
abort(403)
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
password = request.form['password']
|
password = request.form['password']
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,6 @@ def get_post(id, check_author=True):
|
||||||
|
|
||||||
return post
|
return post
|
||||||
|
|
||||||
@bp.route('/<int:id>')
|
|
||||||
def post(id):
|
|
||||||
post = get_post(id, check_author=False)
|
|
||||||
post = dict(post)
|
|
||||||
post['body'] = markdown.markdown(post['body'])
|
|
||||||
return render_template('blog/post.html', post=post)
|
|
||||||
|
|
||||||
@bp.route('/<int:id>/update', methods=('GET', 'POST'))
|
@bp.route('/<int:id>/update', methods=('GET', 'POST'))
|
||||||
@login_required
|
@login_required
|
||||||
def update(id):
|
def update(id):
|
||||||
|
|
@ -108,7 +101,3 @@ def delete(id):
|
||||||
db.execute('DELETE FROM post WHERE id = ?',(id,))
|
db.execute('DELETE FROM post WHERE id = ?',(id,))
|
||||||
db.commit()
|
db.commit()
|
||||||
return redirect(url_for('blog.index'))
|
return redirect(url_for('blog.index'))
|
||||||
|
|
||||||
@bp.route('/temp')
|
|
||||||
def temp():
|
|
||||||
return render_template('temp.html')
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<title>{% block title %}{% endblock %} - {{ config['NAME'] }}</title>
|
<title>{% block title %}{% endblock %} - Flaskr</title>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||||
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
|
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
|
||||||
<nav>
|
<nav>
|
||||||
<h1>{{ config['NAME'] }}</h1>
|
<h1>Flaskr</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{% if g.user %}
|
{% if g.user %}
|
||||||
<li><span>{{ g.user['username'] }}</span>
|
<li><span>{{ g.user['username'] }}</span>
|
||||||
<li><a href="{{ url_for('auth.logout') }}">Log Out</a>
|
<li><a href="{{ url_for('auth.logout') }}">Log Out</a>
|
||||||
|
{% else %}
|
||||||
|
<li><a href="{{ url_for('auth.register') }}">Register</a>
|
||||||
|
<li><a href="{{ url_for('auth.login') }}">Log In</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</br>
|
|
||||||
</br>
|
|
||||||
</br>
|
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<header>
|
<header>
|
||||||
{% block header %}{% endblock %}
|
{% block header %}{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,14 @@
|
||||||
<article class="post">
|
<article class="post">
|
||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1><a href="{{ url_for('blog.post', id=post['id']) }}">{{ post['title'] }}</a></h1>
|
<h1>{{ post['title'] }}</h1>
|
||||||
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
||||||
</div>
|
</div>
|
||||||
{% if g.user['id'] == post['author_id'] %}
|
{% if g.user['id'] == post['author_id'] %}
|
||||||
<a href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
<p class="body">{{ post['body']|safe }}</p>
|
||||||
</article>
|
</article>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block header %}
|
|
||||||
<h1>{% block title %}{{ post['title']}}{% endblock %}</h1>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<article class="post">
|
|
||||||
<header>
|
|
||||||
<div>
|
|
||||||
<h1>{{ post['title'] }}</h1>
|
|
||||||
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
|
||||||
</div>
|
|
||||||
{% if g.user['id'] == post['author_id'] %}
|
|
||||||
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
|
||||||
{% endif %}
|
|
||||||
</header>
|
|
||||||
<p class="body">{{ post['body']|safe }}</p>
|
|
||||||
</article>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@ -8,8 +8,7 @@ dnspython==2.3.0
|
||||||
email-validator==2.0.0.post2
|
email-validator==2.0.0.post2
|
||||||
exceptiongroup==1.1.1
|
exceptiongroup==1.1.1
|
||||||
Flask==2.3.2
|
Flask==2.3.2
|
||||||
-e git+https://gitlab.com/pvtejas/based4tech.git@bda624e4dc1cf97ba2b5b3fcb66a5b28398307bc#egg=flaskr
|
-e git+https://gitlab.com/pvtejas/based4tech.git@3518f50f67c913274f78e2c4b91fe9b7e052ac0d#egg=flaskr
|
||||||
gunicorn==20.1.0
|
|
||||||
h11==0.14.0
|
h11==0.14.0
|
||||||
httpcore==0.17.0
|
httpcore==0.17.0
|
||||||
httptools==0.5.0
|
httptools==0.5.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue