Notes of wgundamj44

last update:

In previous post, I setuped my django develop enviroment with docker. It works fine but with one problem, it use Django’s runserver command to manage all the static files, the page load time is very long, sometimes it even stucks in page loading forever. So I decide to to nginx to replace command of Django. Set up a uwsgi To use python with nginx, uwsgi is our first choice. I created mysite.yaml like the following: uwsgi: socket: 0.0.0.0:8000 master: true no-orphans: true processes: 1 uid: root gid: root chdir: /code # where my django app resides in the docker container env: DJANGO_SETTINGS_MODULE=xxxx # my django setting file module: xxx # my wsgi module buffer-size: 40960 enable-threads: true Several notes here: - root as uid, gid is a bad choice.

I’m using emacs flycheck with pylint to lint my Django project. Everything goes well except I constantly reports import error for my user-defined modules. The system modules are ok, the Django modules are ok too. We know that python uses sys.path to search for modules, so the problem must be python interpreter sees different sys.path value to pylint. So I created a pylintrc file, and put it in the base folder of my project(the folder contains manage.py), in content is: [Master] init-hook='import sys; sys.path.append("/base/folder/of/my/project")' Then I found import error disappears.

boostrap of django Class Apps Everything begins from django.setup(). In this method, it will import django.apps, and as a side effect, apps is created. apps is an instance of django.registry.Apps. This class holds several important fields, all_models which hold all the mapping of from app labels to model. app_configs is all the configurations of app in django. When bootstrapping, apps.populate will be called passing all the apps listed in settings.INSTALLED_APPS. It traverse the apps one by one, and create an AppConfig for each app, and insert it to app_configs.

Transaction in Django atomic @atomic def transaction_func(): pass We know that a decorator will return a wrapper function/class of the decorated function. In Django, the an instance of Atomic class is returned. Atomic is a subclass of ContextDecorator, it is callable because ContextDecorator has a __call__ function. In ContextDecorator’s __call__, we can see something like: @wraps(func, assigned=available_attrs(func)) def inner(*args, **kwargs): with self: return func(*args, **kwargs) return inner So, the wrapped function will be put into a context self.

Develop enviroment with Docker

I used docker-compose to build my develop enviroment. The project consists of MySQL, django and celery(RabbitMQ). So my docker-compose.yml will be something like:

A try on docker

Recently(Last year..) I tried docker a little bit. My Goal was to create my deveopment enviroment of MEAN.js.