A Django project boilerplate/template with lots of state of the art libraries and tools like:
For continuous integration, a CircleCI configuration .circleci/config.yml
is included.
Also, includes a Heroku app.json
and a working Django production.py
settings, enabling easy deployments with 'Deploy to Heroku' button. Those Heroku plugins are included in app.json
:
This is a good starting point for modern Python/JavaScript web projects.
pip install django
, to have the django-admin
command available.django-admin startproject theprojectname --extension py,yml,json --name Procfile,Dockerfile,README.md,.env.example,.gitignore,Makefile --template=https://github.com/vintasoftware/django-react-boilerplate/archive/boilerplate-release.zip
.
right after the project name, using the following command:
django-admin startproject theprojectname . --extension py,yml,json --name Procfile,Dockerfile,README.md,.env.example,.gitignore,Makefile --template=https://github.com/vintasoftware/django-react-boilerplate/archive/boilerplate-release.zip
In the next steps, always remember to replace theprojectname with your project's name
--extension
and --name
params!ADMINS
settings variable in {{project_name}}/backend/{{project_name}}/settings/base.py
SERVER_EMAIL
to the email address used to send e-mails in {{project_name}}/backend/{{project_name}}/settings/production.py
circleci
to .circleci
with the command mv circleci .circleci
After completing ALL of the above, remove this Project bootstrap
section from the project README. Then follow Running
below.
backend
folder, do the following:
{{project_name}}/settings/local.py.example
:cp {{project_name}}/settings/local.py.example {{project_name}}/settings/local.py
.env.example
:cp .env.example .env
/backend/.env
file on a text editor and uncomment the line DATABASE_URL=postgres://{{project_name}}:password@db:5432/{{project_name}}
make docker_setup
users
app:make docker_makemigrations
make docker_migrate
make docker_up
http://localhost:8000
on your browser and the project should be running there
make docker_up
, some containers are spinned up (frontend, backend, database, etc) and each one will be running on a different portmake docker_logs <service name>
(either backend
, frontend
, etc)make docker_down
npm install <package name> --save
The above command will update your
package.json
, but won't make the change effective inside the container yet
requirements.in
or dev-requirements.in
with the newest requirementsmake docker_update_dependencies
to update the containers with the new dependencies
The above command will stop and re-build the containers in order to make the new dependencies effective
npm install
npm run start
Open the /backend/.env
file on a text editor and do one of the following:
DATABASE_URL=sqlite:///backend/db.sqlite3
DATABASE_URL=postgres://{{project_name}}:password@db:5432/{{project_name}}
in order to make it correctly point to your database URL
postgres://USER:PASSWORD@HOST:PORT/NAME
DATABASE_URL
setting for the database you wish to use
DATABASE_URL
for commonly used enginesOpen a new command line window and go to the project's directory
Create a new virtualenv with either virtualenvwrapper or only virtualenv: mkvirtualenv {{project_name}}
or python -m venv {{project_name}}-venv
If you're using Python's virtualenv (the latter option), make sure to create the environment with the suggested name, otherwise it will be added to version control.
Make sure the virtualenv is activated workon {{project_name}}
or source {{project_name}}-venv/bin/activate
Run make compile_install_requirements
to install the requirements
Please make sure you have already setup PostgreSQL on your environment before installing the requirements
In case you wish to use a Conda virtual environment, please remove the line
export PIP_REQUIRE_VIRTUALENV=true; \
fromMakefile
backend
directoryusers
app:python manage.py makemigrations
python manage.py migrate
python manage.py runserver
http://localhost:8000
to see the project runningworkon {{project_name}}
or source {{project_name}}-venv/bin/activate
depending on if you are using virtualenvwrapper or just virtualenv.python manage.py celery
The project expects Mailhog SMTP server to be running on port 1025, you may alter that by changing
EMAIL_PORT
on settings
make test
Will run django tests using --keepdb
and --parallel
. You may pass a path to the desired test module in the make command. E.g.:
make test someapp.tests.test_views
Add the libname to either requirements.in
or dev-requirements.in
, then either upgrade the libs with make upgrade
or manually compile it and then, install.pip-compile requirements.in > requirements.txt
or make upgrade
pip install -r requirements.txt
This project comes with an app.json
file, which can be used to create an app on Heroku from a GitHub repository.
Before deploying, please make sure you've generated an up-to-date requirements.txt
file containing the Python dependencies. This is necessary even if you've used Docker for local runs. Do so by following these instructions.
After setting up the project, you can init a repository and push it on GitHub. If your repository is public, you can use the following button:
If you are in a private repository, access the following link replacing $YOUR_REPOSITORY_LINK$
with your repository link.
https://heroku.com/deploy?template=$YOUR_REPOSITORY_LINK$
Remember to fill the ALLOWED_HOSTS
with the URL of your app, the default on heroku is appname.herokuapp.com
. Replace appname
with your heroku app name.
Sentry is already set up on the project. For production, add SENTRY_DSN
environment variable on Heroku, with your Sentry DSN as the value.
You can test your Sentry configuration by deploying the boilerplate with the sample page and clicking on the corresponding button.
The bin/post_compile
script has a step to push Javascript source maps to Sentry, however some environment variables need to be set on Heroku.
You need to enable Heroku dyno metadata on your Heroku App. Use the following command on Heroku CLI:
heroku labs:enable runtime-dyno-metadata -a <app name>
The environment variables that need to be set are:
SENTRY_ORG
- Name of the Sentry Organization that owns your Sentry Project.SENTRY_PROJECT_NAME
- Name of the Sentry Project.SENTRY_API_KEY
- Sentry API key that needs to be generated on Sentry. You can find or create authentication tokens within Sentry.After enabling dyno metadata and setting the environment variables, your next Heroku Deploys will create a release on Sentry where the release name is the commit SHA, and it will push the source maps to it.
prospector
and npm run lint
on project root.pre-commit install
to enable the hook into your git repo. The hook will run automatically for each commit.git commit -m "Your message" -n
to skip the hook if you need.Some settings defaults were decided based on Vinta's experiences. Here's the rationale behind them:
CELERY_ACKS_LATE = True
We believe Celery tasks should be idempotent. So for us it's safe to set CELERY_ACKS_LATE = True
to ensure tasks will be re-queued after a worker failure. Check Celery docs on "Should I use retry or acks_late?" for more info.
react
for building interactive UIsreact-dom
for rendering the UIreact-router
for page navigationwebpack
for bundling static assetswebpack-bundle-tracker
for providing the bundled assets to Djangobootstrap
for providing responsive stylesheetsreact-bootstrap
for providing components built on top of Bootstrap CSS without using pluginsnode-sass
for providing compatibility with SCSS filesaxios
for performing asynchronous callscookie
for easy integration with Django using the csrftoken
cookieredux
for easy state management across the applicationconnected-react-router
for integrating Redux with React Routerhistory
for providing browser history to Connected React Routerreact-redux
for integrating React with Reduxredux-devtools-extension
for inspecting and debugging Redux via browserredux-thunk
for interacting with the Redux store through asynchronous logiclodash
for general utility functionsclassnames
for easy working with complex CSS class names on componentsprop-types
for improving QoL while developing providing basic type-checking for React propsreact-hot-loader
for improving QoL while developing through automatic browser refreshingdjango
for building backend logic using Pythondjangorestframework
for building a REST API on top of Djangodjango-webpack-loader
for rendering the bundled frontend assetsdjango-js-reverse
for easy handling of Django URLs on JSpsycopg2
for using PostgreSQL databasesentry-sdk
for error monitoringpython-decouple
for reading environment variables on settings filescelery
for background worker tasksdjango-debreach
for additional protection against BREACH attackwhitenoise
and brotlipy
for serving static assetsIf you wish to contribute to this project, please first discuss the change you wish to make via an issue.
Check our contributing guide to learn more about our development process and how you can test your changes to the boilerplate.
This project, as other Vinta open-source projects, is used in products of Vinta clients. We are always looking for exciting work, so if you need any commercial support, feel free to get in touch: contact@vinta.com.br
Copyright (c) 2021 Vinta Serviços e Soluções Tecnológicas Ltda.
The author selected the Mozilla Foundation to receive a donation as part of the Write for DOnations program. 作者选择Mozilla基金会作为Write for DOnations计划的一部分接受捐赠。 介绍 (Introduction) As demand for full-stack d
一、下面先说一下linuxmint 19.2装python3.6.8怎么设置成默认python版本: 删除原来的链接到2.7的文件,然后链接到3.6 sudo rm /usr/bin/python sudo ln /usr/bin/python3.6 /usr/bin/python 二、需要linuxmint python>原装3.6.8版本,从下载到配置: 安装需要的程序包 $ sudo apt
参考django3新建第一个项目(详情django3新建项目可查看这个目录) 1.安装python3 pip install django pip install djangorestframework (django序列化数据) pip install django-cors-headers (django 跨域) 2. django-admin startproject vue-django
django 运行服务器使用 python manage.py runserver 0.0.0.0:8000 settings中配置 ALLOWED_HOSTS = ["*"] 中间件注释掉跨域攻击 MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.m
This is a very simple blog built with Django, Django REST Framework, React/Redux, and Bootstrap, deployed with Docker, and served with nginx-uwsgi. It can be useful as an example of integrating Django
我想从React获取数据到Django后端,并用'request'请求url中的参数。收到获取(“,无)”[或备选方案?]。最好的情况是针对多个参数或体内的解决方案。每个教程都只显示fetch to模型,但我为request或create()找到的所有引用都是视图中的参数。py(在视图中使用值执行其他操作)不起作用。 我想从url中刮取'name'(在接下来的步骤中,我也需要'params'从bo
我目前正在做一个使用Django API服务器和运行React的NodeJS服务器的项目。在开发中,我们在8000端口上运行Django,在8080端口上运行NodeJS,目前React负责渲染页面并与Django API交互,Django API为React提供数据。为了让React调用Django API,我们在Django中启用了CORS,因为它们位于不同的端口上。 我的问题如下: > 允许
问题内容: 这是一个教育项目,不用于生产。我本来不想让用户登录。 我可以在没有用户登录的情况下使用CSRF令牌对Django进行POST调用吗?我可以不使用jQuery来做到这一点吗?我在这里不了解我的观点,并且肯定会混淆一些概念。 在JavaScript方面,我找到了这个redux-csrf软件包。我不确定如何将其与POST使用Axios的操作结合使用: 在Django方面,我已经阅读了有关CS
我很难弄清楚石墨烯Django应该如何与react路由器中继一起使用。假设我可以通过Django服务器上的GraphiQL控制台很好地使用以下GraphQL查询: 这可能是Graphene对commmon查看器的替代,因为Relay不支持根查询上的连接。因此,我知道allThreads实际上是一个节点(类型为ThreadNodeConnection),并且有一个可以查询的边连接。 问题是我不知道如
PyCharm的一个特性是它包含对Django的支持。 能够在PyCharm中包含JavaScript功能,它可以被认为是Django的最佳IDE。 在PyCharm IDE中创建Django项目的基本步骤如下 - 如果启用了EnableDjangoadmin选项,PyCharm将为您设置管理站点。 模板调试 调试适用于Django和Jinja模板。 我们可以检查变量,逐步执行代码,并在调试器中执