当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

tedivms-flask

授权协议 BSD-2-Clause License
开发语言 Python
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 高兴贤
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

tedivm's flask starter app

Screenshot

This code base serves as starting point for writing your next Flask application.

This package is designed to allow developers to start working on their specific features immediately while also making it simple to deploy the project into production. It contains a number of configured extensions and libraries as well as unique features specifically built for this package. It also is completely dockerized, with both a docker-compose testenv and the ability to easily make images off of the application for pushing into production.

Code characteristics

  • Tested on Python 3.3, 3.4, 3.5, 3.6, and 3.7
  • Complete docker environment.
  • Images for both the web application and the celery worker.
  • Full user management system.
  • Server side session storage.
  • An API system with API tokens and route decorators.
  • Well organized directories with lots of comments.
  • Includes test framework (py.test and tox)
  • Includes database migration framework (alembic, using Flask-Migrate)
  • Sends error emails to admins for unhandled exceptions

Configured Extensions and Libraries

With thanks to the following Flask extensions and libraries:

  • Beaker for caching and session management.
  • Celery for running asynchronous tasks on worker nodes.
  • Click for the creation of command line tools.
  • Flask the microframework framework which holds this all together.
  • Flask-Login allows users to login and signout.
  • Flask-Migrate integrates Alembic into Flask to handle database versioning.
  • Flask-SQLAlchemy integrates SQLAlchemy into Flask for database modeling and access.
  • Flask-User adds user management and authorization features.
  • Flask-WTF integrates WTForms into Flask to handle form creation and validation.

In addition the front end uses the open source versions of:

Unique Features

  • Database or LDAP Authentication - Applications built with this project can use the standard database backed users or can switch to LDAP authentication with a few configuration settings.

  • API Authentication and Authorization - this project can allow people with the appropriate role to generate API Keys, which in turn can be used with the roles_accepted_api decorator to grant API access to specific routes.

  • Versatile Configuration System - this project can be configured with a combination of configuration files, AWS Secrets Manager configuration, and environmental variables. This allows base settings to be built into the deployment, secrets to be managed securely, and any configuration value to be overridden by environmental variables.

  • A makefile with a variety of options to make common tasks easier to accomplish.

  • A Celery based asynchronous task management system. This is extremely useful for long running tasks- they can be triggered in the web interface and then run on a worker node and take as long as they need to complete.

Setting up a development environment

First we recommend either cloning this repository with the "Use this template" button on Github.

We assume that you have make and docker.

# Clone the code repository into ~/dev/my_app
mkdir -p ~/dev
cd ~/dev
git clone https://github.com/tedivm/tedivms-flask my_app
cd my_app

# For the first run, and only the first run, we need to create the first round of SQLAlchemy models.
make init_db

# Create the 'my_app' virtual environment and start docker containers
make testenv

# Restart docker app container
docker-compose restart app

# Start a shell in the container running the application
docker-compose exec app /bin/bash

Configuration

Application configuration

To set default configuration values on the application level- such as the application name and author- edit ./app/settings.py. This should be done as a first step whenever using this application template.

Configuration File

A configuration file can be set with the environmental variable APPLICATION_SETTINGS.

AWS Secrets Manager

Configuration can be loaded from the AWS Secrets Manager by setting the environmental variables AWS_SECRETS_MANAGER_CONFIG and AWS_SECRETS_REGION.

Environmental Variables

Any environmental variables that have the same name as a configuration value in this application will automatically get loaded into the app's configuration.

Configuring LDAP

Any installation can run with LDAP as its backend with these settings.

USER_LDAP=true
LDAP_HOST=ldap://ldap
LDAP_BIND_DN=cn=admin,dc=example,dc=org
LDAP_BIND_PASSWORD=admin
LDAP_USERNAME_ATTRIBUTE=cn
LDAP_USER_BASE=ou=users,dc=example,dc=org
LDAP_GROUP_OBJECT_CLASS=posixGroup
LDAP_GROUP_ATTRIBUTE=cn
LDAP_GROUP_BASE=ou=groups,dc=example,dc=org
LDAP_GROUP_TO_ROLE_ADMIN=admin
LDAP_GROUP_TO_ROLE_DEV=dev
LDAP_GROUP_TO_ROLE_USER=user
LDAP_EMAIL_ATTRIBUTE=mail

Initializing the Database

# Initialize the database. This will create the `migrations` folder and is only needed once per project.
make init_db

# This creates a new migration. It should be run whenever you change your database models.
make upgrade_models

Running the app

# Start the Flask development web server
make testenv

Point your web browser to http://localhost/

You can make use of the following users:

  • email user@example.com with password Password1.
  • email dev@example.com with password Password1.
  • email admin@example.com with password Password1.

Running the automated tests

# To run the test suite.
make run_tests

Acknowledgements

Flask-Dash was used as a starting point for this code repository. That project was based off of the Flask-User-starter-app.

Authors

  • Robert Hafner (tedivms-flask) -- tedivm@tedivm.com
  • Matt Hogan (flaskdash) -- matt AT twintechlabs DOT io
  • Ling Thio (flask-user) -- ling.thio AT gmail DOT com
 相关资料
  • 问题内容: 在服务器端,我只是将json-as-dictionary打印到控制台 现在,每当我通过ajax发出发布请求时,控制台都会打印出包含我所需内容的字典。 在客户端,我一直在尝试使用各种方法来基于成功的ajax调用执行一些jquery。我只是意识到这可能是服务器端的错误,即我没有发送任何请求标头来告诉jquery其ajax调用成功。 那么,如何将OK状态发送回给客户以告诉一切一切正常? 为了

  • 问题内容: 我有一个生成数据并实时流式传输的视图。我不知道如何将数据发送到可以在HTML模板中使用的变量。我当前的解决方案只是在到达数据时将数据输出到空白页,这是可行的,但是我想将其包含在具有格式化功能的较大页面中。在流式传输到页面时如何更新,格式化和显示数据? 问题答案: 此示例假定一种非常简单的消息格式:一行数据,然后是换行符。当然,只要有一种识别每条消息的方法,解析就可能变得很复杂。例如,你

  • 问题内容: 我跑步时得到警告。 所以我使用安装了flask_mysql ,成功安装了它,但是当我运行时出现错误。在第一个警告中我也得到了 。您能告诉我如何将其重命名为flask_mysql吗?提前致谢。 问题答案: 是已弃用的模式,在较旧的扩展程序和教程中广泛使用。警告是告诉您将其替换为直接导入(它可能是)。但是,Flask- MySQL使用了更加过时的模式。除了说服维护人员发布可修复该问题的新版

  • 问题内容: 我有一个唯一依赖的应用程序是flask,它可以在docker外部正常运行并绑定到默认端口5000。这是完整的源代码: 问题是,当我在docker中部署此服务器时,服务器正在运行,但无法从容器外部访问。 以下是我的Dockerfile。该图像是装有烧瓶的ubuntu。焦油仅包含index.py上面列出的内容; 这是我正在部署的步骤 据我所知,上面的程序运行良好,图像中包含tar的内容/s

  • 问题内容: 我想返回渲染的页面和可下载的文件作为对请求的响应。我试图返回两个响应的元组,但是它不起作用。如何提供下载和页面? Flask是否有能力应对这种情况?似乎是一个普通问题,我只是想将文件发送回下载,然后呈现页面。 问题答案: 您不能将多个响应返回到单个请求。取而代之的是,生成文件并将其存储在某个位置,并通过另一条路径来提供服务。返回呈现的模板,并提供一个网址以提供该文件的路径。 在模板中,

  • 问题内容: 我是Flask的新手,我想确保Redis服务器正在运行,如果没有运行,请启动它。这是我所拥有的: 但是,我收到一个错误“ OSError:[Errno 2]没有这样的文件或目录” 有没有更简单的方法来检查Redis服务器是否正在运行? 问题答案: 使用 ping cmd的redis: 样本输出: