Some Django development experience

Some developers Django experience
base

Use virtualenv isolated development environment

Use pip manage project dependencies, mainly a trick, use pip freeze> requirements.txt to save the dependent modules and versions

Use gitignore.io This site provides .gitignore file management code library file

Packaging and distribution
packaging and publishing projects Docker, Django project with the Dockerfile particularly simple:

FROM python:3.5
COPY ./requirements.txt /src
WORKDIR /src
RUN pip install -r requirements.txt
COPY . /src
EXPOSE
CMD uwsgi --http :--wsgi-file<path/to/wsgi.py>

This template can be a Dockerfile 80% of take-Django project.

Logging Configuration
Now with Docker, he gave up the log file is written directly to standard output.

settings.py

...

























Automated testing
Since it is a pure back-end projects, engineers can be detected by automated testing their own code. Django itself provides good support for testing, you can build a test database through sqlite, there are memory-based cache, do not increase dependence on other test systems. Develop them more efficiently.

In addition to automated test code to write, but also to statistical test coverage. Currently we are using this tool coverage.py, to be honest there is no easy node.js of istanbul, report output is not detailed and easy to read Istanbul. But to check "dead code" is sufficient.

Http test code for
some third-party systems project needs more docking, such as micro-channel authentication, payment, text messages and other common, there are other systems might vertical business areas. This part of the docking interface code should also be incorporated into the tests, after all Python as a scripting language, the code is very prone to error.

This is generally the module responses mock http request.

Regular tasks
There are some Django projects need to do some regular tasks. First of all, absolutely no built-in linux crontab. The main problem is the high cost of maintenance, maybe someday put this configuration to forget.

We are now way by means of Django Command functions, timed task will be packaged into a command. A scheduler to run this command inside. Like this:

import schedule
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **kwargs):
schedule.every(45).minutes.do(do_this)
schedule.every().day.at('04:00').do(do_that)
while True:
schedule.run_pending()
time.sleep(1)

Guess you like

Origin www.cnblogs.com/bbiu/p/11265782.html