Skip to content
Snippets Groups Projects
Commit fc259911 authored by Lukas Böhm's avatar Lukas Böhm :8ball:
Browse files

initial commit

parents
Branches master
No related tags found
No related merge requests found
# python and IDE files
venv/
__pychache__/
.idea/
*.pyc
# data
home.db
media/
data/
.env
# logs and temp stuff
*.tmp
*.temp
log.txt
errlog.txt
FROM python:3.8-alpine
WORKDIR /home/<APP_NAME>
# get python ready
COPY ./requirements.txt ./requirements.txt
RUN pip install -r requirements.txt
RUN pip install gunicorn
# copy actual app
COPY app app
COPY server.py server.py
ENV FLASK_APP server.py
EXPOSE 5000
ENTRYPOINT gunicorn -b localhost:5000 --workers=3 --timeout=90 --graceful-timeout=30 --log-level=DEBUG --access-logfile - --error-logfile - server:app
# Flask Application Template
## How to use the template
call `sh replace.sh` and follow the instructions
It will basically replace <DOMAIN> and <APP_NAME> in the entire app.
PLEASE manually edit web.conf and web.service.
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv
from flask_migrate import Migrate
load_dotenv()
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
app = Flask(__name__)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY') or 'jonas ist ein kek'
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI') or 'sqlite:///' + os.path.join(basedir, 'home.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from app.models import *
from app import routes
from wtforms import StringField, SubmitField, SelectField, MultipleFileField, BooleanField, PasswordField
from wtforms.validators import DataRequired, Optional, length
from flask_wtf import FlaskForm
class User(FlaskForm):
name = StringField('Name', validators=[Required(), length(max=64)])
submit = SubmitField('Hochladen')
from app import db
class User(db.Model):
__tablename__ = 'User'
id = db.Column('ID', db.Integer, primary_key=True, unique=True, nullable=False)
name = db.Column('Name', db.String(64), nullable=True)
def __repr__(self):
return f'<Share {self.name}>'
import os
from datetime import timezone, datetime, timedelta
from app import app, db
from flask import redirect, url_for, render_template, send_from_directory, current_app, session, flash
@app.route('/')
def index():
return render_template('Hello.html')
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="<APP_NAME>">
{% block preview %}
<meta property="og:type" content="website">
<meta property="og:url" content="https://<DOMAIN>">
<meta property="og:title" content="<APP_NAME>">
<meta property="og:description" content="TODO">
{% endblock preview %}
<title>{% block title %} <APP_NAME> {% endblock title %}</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</head>
<body>
<!-- page contents in here -->
{% block page %}
{% endblock page %}
</body>
</html>
\ No newline at end of file
{% extends "Base.html" %}
{% block page %}
<!-- Navbar -->
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
<h5 class="my-0 mr-md-auto font-weight-normal"><APP_NAME></h5>
</div>
<div class="container">
{% include 'include/messages.html' %}
<!-- actual content -->
{% block content %}
{% endblock content %}
<!-- end actual content -->
</div>
<!-- Footer -->
<footer class="pt-4 my-md-5 pt-md-5 border-top">
<div class="footer-copyright text-center py-3">
<small class="d-block mb-3 text-muted text-center">Chief Corporation &copy; 2020</small>
</div>
</footer>
{% endblock page %}
{% extends 'BasePage.html' %}
{% block content %}
<div class="pricing-header px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Fehler {{ e.code }} - {{ e.name }}</h1>
<p class="lead">Es tut uns leid, aber es ist etwas schief gelaufen.</p>
<small class="d-block mb-3 text-muted">{{ e.description }}</small>
</div>
{% endblock content %}
{% extends 'BasePage.html' %}
{% block content %}
<h1>Hallo</h1>
{% endblock content %}
{% with messages = get_flashed_messages(with_categories=true) %}
{% for category, message in messages %}
{# category being: (lowercase!!!)
success
info
warning
danger
primary
secondary
dark
#}
<div class="alert alert-{{ category }} alert-dismissible fade show">
<button type="button" class="close" data-dismiss="alert">&times;</button>
{{ message }}
</div>
{% endfor %}
{% endwith %}
\ No newline at end of file
#!/bin/bash
echo -n "Please set the domain, e.g localhost (replaces <DOMAIN>): "
read domain
echo -n "Please set the app-name e.g chieftest (replaces <APP_NAME>): "
read appname
find . -type f -exec sed -i "s/<APP_NAME>/$appname/g" {} \;
find . -type f -exec sed -i "s/<DOMAIN>/$domain/g" {} \;
from app import app
\ No newline at end of file
[Unit]
Description=<APP_NAME> Web Service Worker
[Service]
Type=simple
WorkingDirectory=/home/<USER>/<APP_NAME>
ExecStart=/home/<USER>/<APP_NAME>/venv/bin/gunicorn -b localhost:5000 --workers=3 --access-logfile /home/<USER>/<APP_NAME>/logs/access.log --error-logfile /home/<USER>/<APP_NAME>/logs/err.log server:app --timeout 200
Restart=on-failure
[Install]
WantedBy=default.target
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment