All Projects → jambonrose → python-web-dev-21-2

jambonrose / python-web-dev-21-2

Licence: other
Material for "Web Development in Python with Django" using Django 2.1, published as a Pearson LiveLesson on Safari Books Online

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to python-web-dev-21-2

Project Dashboard With Django
Agile Project Management dashboard with Django REST and Vue.js
Stars: ✭ 25 (-34.21%)
Mutual labels:  heroku, django-rest-framework
Covid19 Dashboard
🦠 Django + Plotly Coronavirus dashboard. Powerful data driven Python web-app, with an awesome UI. Contributions welcomed! Featured on 🕶Awesome-list
Stars: ✭ 100 (+163.16%)
Mutual labels:  heroku, django-application
Ponee
A lightweight Django template ready for Heroku
Stars: ✭ 41 (+7.89%)
Mutual labels:  heroku, django-rest-framework
heroku-flask-template
A simple, fast and easy-to-deploy Heroku ready flask web app template written in Python.
Stars: ✭ 26 (-31.58%)
Mutual labels:  heroku, herokuapp
Bistu
集成了 django-simpleui 作为 admin 管理主题,实现的一个小型的管理系统,并且有的 django-rest-framework 使用示例。此外有个 Bistu-Ant-Design-Pro 项目作为配套的前端使用。如果喜欢记得给个🌟star哦。
Stars: ✭ 51 (+34.21%)
Mutual labels:  django-rest-framework, django-application
mTracker
An email tracker built with Python and Flask
Stars: ✭ 20 (-47.37%)
Mutual labels:  heroku, herokuapp
Generator Django Rest
Yeoman generator for a Django REST/GraphQL API, an optional React SPA & lots more!
Stars: ✭ 77 (+102.63%)
Mutual labels:  heroku, django-rest-framework
Thinkdiff
My open source project links, programming and software development related code and tutorials are in this repo. Content types: Python, JavaScript, Dart | Django, React, Flutter, React-Native etc.
Stars: ✭ 65 (+71.05%)
Mutual labels:  django-rest-framework, django-application
drf-addons
Some customised Django classes and functions that one can use in DJango. Collected from internet!
Stars: ✭ 20 (-47.37%)
Mutual labels:  django-rest-framework, django-application
matchering-web
🎚️ Self-Hosted LANDR / eMastered Alternative
Stars: ✭ 25 (-34.21%)
Mutual labels:  django-rest-framework, django-application
Django Rest Registration
User-related REST API based on the awesome Django REST Framework
Stars: ✭ 240 (+531.58%)
Mutual labels:  django-rest-framework, django-application
Deep-learning-model-deploy-with-django
Serving a keras model (neural networks) in a website with the python Django-REST framework.
Stars: ✭ 76 (+100%)
Mutual labels:  django-rest-framework, django-application
Education Backend
Django backend for my info-business website
Stars: ✭ 79 (+107.89%)
Mutual labels:  django-rest-framework, django-application
matorral
An open-source, very simple & extensible project managent tool written using Django/Python
Stars: ✭ 21 (-44.74%)
Mutual labels:  heroku, herokuapp
Awesome Django
Repository mirror of GitLab: https://gitlab.com/rosarior/awesome-django This repository is not monitored for issues, use original at GitLab.
Stars: ✭ 8,527 (+22339.47%)
Mutual labels:  django-rest-framework, django-application
Django Rest React Pycon
🐍 Demo repo for Pycon X talk "Decoupling Django with Django REST (and a sprinkle of React)"
Stars: ✭ 72 (+89.47%)
Mutual labels:  heroku, django-rest-framework
Djangorestframework Book
Django REST framework 3 中文文档, API参考, 最佳实践指南
Stars: ✭ 28 (-26.32%)
Mutual labels:  django-rest-framework, django-application
Algo Phantoms Backend
💻 Algo-Phantoms-Backend is an Application that provides pathways and quizzes along with a code editor to help you towards your DSA journey.📰🔥 This repository contains the REST APIs of the application.✨
Stars: ✭ 36 (-5.26%)
Mutual labels:  django-rest-framework, django-application
Crud App Vuejs Django
This is simple crud app and searchFilter made using vuejs and django. Used to explain the tutorial present on https://medium.com/@shubhambansal_89125/crud-app-using-vue-js-and-django-516edf4e4217 https://medium.com/@shubhambansal_89125/searchfilter-using-django-and-vue-js-215af82e12cd
Stars: ✭ 174 (+357.89%)
Mutual labels:  heroku, django-rest-framework
Meteor-Files-Demo
Demo application for ostrio:files package
Stars: ✭ 16 (-57.89%)
Mutual labels:  heroku, herokuapp

Read Me

This repository contains the code for the second class in Andrew Pinkham's Python Web Development series, titled Building Backend Web Applications and APIs with Django. The series is published by Pearson and may be bought on InformIT or viewed on Safari Books Online. The series is for intermediate programmers new to web development or Django.

Andrew may be reached at JamBon Software for consulting and training.

Table of Contents

Changes Made Post-Recording

  1. For security purposes a commit has been added at the end of every branch which secures the application using basic login functionality. The content of that commit will be discussed in the third Python Web Development class - I hope you're looking forward to it!
  2. Test dependencies have been included in all branches, so that the Docker image may be built once and used on all branches.
  3. The Docker image has been updated to use Python 3.7.1 (from 3.7.0)
  4. Pre-Commit and Black have been updated to more recent versions
  5. The site uses Django's StaticFilesStorage instead of the ManifestStaticFilesStorage shown in Lesson 7 by error.

🔝 Up to Table of Contents

Technical Requirements

All other technical requirements are installed by pip using the requirement files included in the repository. This includes Django 2.1.

🔝 Up to Table of Contents

Getting Started Instructions

For a full guide to using this code please refer to Lesson 2 of the class. This lesson demonstrates how to get started locally as well as how to use the Docker setup.

If you are unable to run Docker on your machine skip to the Local Setup section.

Docker Setup

The use of Docker images allows us to avoid installing all of our dependencies—including PostgeSQL—locally. Furthermore, as discussed in the videos, it helps with parity between our development and production environments.

Our Docker containers expect the existence of an environment file. To generate it on *nix systems please invoke the build_docker_env.sh script.

./build_docker_env.sh

On Windows please invoke the batch file.

build_docker_env

If you run into problems please refer to the videos for why we use this and what is needed in the event these scripts do not work.

To run the Docker containers use the command below.

docker-compose up

If you wish to run the servers in the background use the -d (detached) flag, as demonstrated below.

docker-compose up -d

To turn off the server use Control-C in the terminal window. If running in the background use the command below.

docker-compose down

To remove all of the assets created by Docker to run the server use the command below.

docker-compose down --volumes --rmi local

The --volumes flag may be shortened to -v.

🔝 Up to Table of Contents

Local Setup

Use pip to install your development dependencies.

$ python3 -m pip install -r requirements/development.txt

If you have checked out to an earlier part of the code note that you will need to use requirements.txt instead of requirements/development.txt.

You will need to define theSECRET_KEY environment variable. If you would like to use PostgreSQL locally you will need to set DATABASE_URL.

export SECRET_KEY=`head -c 75 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 50`
# replace the variables in <> below
export DATABASE_URL='postgres://<USER>:<PASSWORD>@<SERVER>:5432/<DB_NAME>'

Please be advised that if you are running code in Lesson 2 you should expect to see errors. Lesson 2 changes the database structure but avoids making migrations until the very last moment. What's more, database settings change in Lesson 2.8. Errors are therefore normal!

🔝 Up to Table of Contents

Walking the Repository

To make perusing the code in this repository as simple as possible the project defines its own .gitconfig file with custom commands (aliases).

To enable the commands you must first point your local git configuration at the file provided. Either of the two commands below should work.

# relative path
git config --local include.path "../.gitconfig"
# absolute path - *nix only!
git config --local include.path "`builtin pwd`/.gitconfig"

This will enable the following git commands:

  • git next: Move to the next example/commit
  • git prev: Move to the previous example/commit
  • git ci: shortcut for git commit
  • git co: shortcut for git checkout
  • git st: shortcut for git status
  • git ll: shortcut for git log --oneline

These commands can be used on any of the two branches in this repository, which are listed below.

  • class_material: contains the code and material seen in the videos, as well as solutions to exercises mentioned in Lessons 5 and 6 (see section below to review).
  • with_tests: includes material above, as well as the tests used by me to verify the code works

🔝 Up to Table of Contents

Extra Problems

At the end of Lessons 5 and 6 I leave you with several optional exercises.

In Lesson 5:

  • Create new NewsLink objects in API via POST method (Consider ViewSets vs APIView subclasses)
  • Simplify PostSerializer with HyperlinkedRelatedField (as seen on NewsLinkSerializer)
  • Use ViewSets and Routers to simplify Post handling in API

In Lesson 6:

  • Use CreateView, UpdateView, and DeleteView to create views for Startup and Post objects (using StartupForm and PostForm)
  • Create a view to create new NewsLink objects and associate them automatically with Startup objects
  • Expand this view to handle updating NewsLink objects
  • Allow for NewsLink objects to be deleted

Below are a few other tasks to test your knowledge.

  • Create links in the templates to enable easier navigation across the site
  • Create a welcome page for the API (see the use of DefaultRouter)

The solutions to all of the tasks above can be found in the class_material git branch or on Github.

🔝 Up to Table of Contents

Testing the Code

All of the tests used to build the code can be found in the with_tests branch on Github.

The branch (mostly) emulates a Test Driven-Development approach: commits prefixed with test write a test that will fail, while commits with lesson numbers then fix the failing tests from previous test commits.

To run the tests locally use manage.py.

# from root of project
cd src
python3 manage.py test

Tests may also be run in Docker.

# from root of project
docker-compose run --rm django python manage.py test

Be advised that running tests in Lesson 2 is tricky. You will generally need to create migrations before being able to run the tests, and there are a few commits that break the project's ability to run tests (such as when changing the database settings).

We will cover material about how to test Django in the next Python Web Development class. I hope you're looking forward to it!

🔝 Up to Table of Contents

Deploying the Code

The project follows 12 Factor App principles and is configured to be deployed to Heroku.

To start you will need to sign up for Heroku unless you already have an account. Make sure you have installed the Heroku CLI.

The following instructions are for *nix systems, and will need to be adapted for Windows.

Ensure your app is ready for deployment.

docker-compose run --rm django python manage.py check --deploy --settings="config.settings.production"

From the command line create a new app.

$ heroku create

Heroku will give your app a random name (such as infinite-tundra-77435). Assign this name to a variable to be able to use commands below.

$ export APP='infinite-tundra-77435' # replace with your actual app name

Your git repository should now have a new remote branch named heroku. If it is missing you can add it manually.

$ heroku git:remote -a $APP

Create a PostgreSQL database for your app.

$ heroku addons:create -a "$APP" heroku-postgresql:hobby-dev

Configure your app to use production settings.

$ heroku config:set -a "$APP" DJANGO_SETTINGS_MODULE='config.settings.production'
$ heroku config:set -a "$APP" SECRET_KEY="$(head -c 75 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 50)"
$ heroku config:set -a "$APP" PYTHONHASHSEED=random
$ heroku config:set -a "$APP" WEB_CONCURRENCY=2

You may now deploy your app.

$ git push heroku class_material:master
$ # you can also deploy the other branch to Heroku using:
$ git push heroku with_tests:master

To create a new user use the command below.

$ heroku run -a $APP python src/manage.py createsuperuser

To access the remote shell (to create data on the fly) use the command below.

$ heroku run -a $APP python src/manage.py shell_plus

To see the app online you may use the command below.

$ heroku open -a $APP

For more about what we've just done please see Heroku's Getting Started with Python documentation. If Lesson 7 does not cover as much material as you'd like you may be interested in Chapter 29 of Django Unleashed.

🔝 Up to Table of Contents

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].