Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)

License

NotificationsYou must be signed in to change notification settings

duduknecmi/Build_Backend_REST_API_with_Python_and_Django

 
 

Repository files navigation

License: UnlicenseBuild StatusCodacy Badge

Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)

Table of Contents

  1. About

  2. Main Objectives

  3. Tech Topics Covered

  4. Icons Library

  5. Official Web Resources

  6. Additional Resources

  7. Tech Issues and Problem Solving

  8. Django App:

About

The advanced course on how to Build a Backend REST API using Python, Django (2.0), Django REST Framework (3.9), Docker, Travis CI, Postgres and Test Driven Development!

The original course content was created byMark Winterbottom.

The main goal is to built a fully functioning REST API that can handle

  • User authentication
  • Creating objects
  • Filtering and sorting objects
  • Uploading and viewing images

Additional topics covered

  • Setup a project with Docker and Docker-Compose
  • Configure Travis-CI to automatically run linting and unit tests
  • Write unit tests using the Django Test Framework
  • Apply best practice principles including Test Driven Development
  • Handle uploading media files with Django
  • Customize the Django admin
  • Configure a Postgres database

Official Web Resources

Additional Resources

Tech Issues and Problem Solving

Changing the project interpreter in the PyCharm project settings
  1. In theSettings/Preferences dialog (Ctrl+Alt+S), selectProject | Project Interpreter.
  2. Expand the list of the available interpreters and click theShow All link.
  3. Select the target interpreter. When PyCharm stops supporting any of the outdated Python versions, the corresponding project interpreter is marked as unsupported.
  4. The Python interpreter name specified in theName field, becomes visible in the list of available interpreters. ClickOK to apply the changes.

For more info pleasecheck here

PyCharm - Choosing Your Testing Framework
  1. Open the Settings/Preferences dialog, and under the node Tools, click the pagePython Integrated Tools.
  2. On this page, click theDefault Test Runner field.
  3. Choose the desired test runner:

For more info please seeEnable Pytest for you project

Setting up Python3 virtual environment on Windows machine
  1. open CMD
  2. navigate to project directory, for example:
cd C:\Users\superadmin\Desktop\Python\CodinGame
  1. run following command:
pip install virtualenv
  1. run following command:
virtualenv venv --python=python
Setting up Python3 virtual environment on Linx (Ubuntu) machine

How to install virtualenv

  1. Installpip first
    sudo apt-get install python3-pip
  1. Then installvirtualenv using pip3
    sudo pip3 install virtualenv
  1. Now create a virtual environment
    virtualenv venv

you can use any name insted ofvenv

  1. You can also use a Python interpreter of your choice:
    virtualenv -p /usr/bin/python2.7 venv
  1. Active your virtual environment:
source venv/bin/activate
  1. Using fish shell:
source venv/bin/activate.fish
  1. To deactivate:
    deactivate
  1. Create virtualenv using Python3:
    virtualenv -p python3 myenv
  1. Instead of using virtualenv you can use this command in Python3:
    python3 -m venv myenv

Source

Activate Virtual Environment

In a newly created virtualenv there will be a bin/activate shell script. For Windows systems, activation scripts are provided for CMD.exe and Powershell.

  1. Open Terminal
  2. Run: \path\to\env\Scripts\activate

Source

Auto generate requirements.txt

Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once.
Use pip’s freeze command to generate a requirements.txt file for your project:

pip freeze> requirements.txt

If you save this in requirements.txt, you can follow this guide:PyCharm - Manage dependencies using requirements.txt, or you can:

pip install -r requirements.txt

Source

error: RPC failed; curl 56 Recv failure: Connection was reset
  1. Open Git Bash
  2. Run: "git config --global http.postBuffer 157286400"

Source

How to fix in case .gitignore is ignored by Git

Even if you haven't tracked the files so far, Git seems to be able to "know" about them even after you add them to .gitignore

NOTE:

  • First commit your current changes, or you will lose them.
  • Then run the following commands from the top folder of your Git repository:
git rm -r --cached.git add.git commit -m"fixed untracked files"
How to generate Allure report with history trends (Windows OS)


Step by step:

  1. Run tests from pytest using following arguments: -v --alluredir=allure-results
  2. Copy '.\allure-report\history' folder into '.\allure-results\history'
  3. Run: allure generate .\allure-results\ -o .\allure-report\ --clean
  4. Following output should appear: Report successfully generated to .\allure-report
  5. Run: allure open .\allure-report\

Source

Sphinx Documentation Set Up


Step by step:

  1. Create docs directory

  2. Open cmd > Go to docs directory

  3. cmd > Run: sphinx-quickstart.Note: run with default answers

  4. Go to docs/conf.py

  5. Uncomment following lines:

importosimportsyssys.path.insert(0,os.path.abspath('.'))
  1. Update extensions list as following:
extensions= ['sphinx.ext.todo','sphinx.ext.viewcode','sphinx.ext.autodoc']
  1. Update template as following:
html_theme='sphinx_rtd_theme'
  1. Update sys.path.insert as following:
sys.path.insert(0,os.path.abspath('..'))
  1. Go to docs/index.rst > add modules, see example below:
.. toctree::   :maxdepth: 2   :caption: Contents:   modules
  1. Open cmd > run:
sphinx-apidoc-o . ..
  1. cmd > Run: make html
  2. Install html template:
pipinstallsphinx_rtd_theme

Video TutorialSphinx DocumentationMore Info

Auto-Generated Python Documentation with Sphinx


Step by step:

  1. Open CMD
  2. Go to docs directory
  3. Run: make clean
  4. Run: make html

Source

About

Create an advanced REST API with Python, Django REST Framework and Docker using Test Driven Development (TDD)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python97.9%
  • Dockerfile2.1%

[8]ページ先頭

©2009-2025 Movatter.jp