[PYTHON] Take a look at Django's template.

Try Python's Django 1.9 Project template.

I thought that I was studying the configuration of Django, and when I searched on Github, it seemed interesting, so I tried it. This is my first time to do a start project based on django's project template.

See Github Sam's Django Project Template

Originally it seems like this. It is based on the project_template shipped with stable/1.5.x and modified for Django 1.9.

feature is,

  1. It is set assuming the development environment and the production environment. --The debug toolbar is set. --D is postgresql. (I tried it in 9.5) --wsgi (production --setteing.py is also divided into production and development. --Grappelli (It feels like a CMS enhancement tool on the admin page) <= This looks interesting.

Preparation

install postgresql

sudo apt-get install postgresql-9.5
sudo apt-get install  postgresql-server-dev-9.5

Follow the procedure

virtualenv setting (hereinafter implemented with virtualenv)

$ virtualenv env
$ source env/bin/activate

pip install $ pip install -r https://raw.github.com/sjkingo/django-project-template/master/requirements.txt $ pip install -r https://raw.github.com/sjkingo/django-project-template/master/requirements-dev.txt

Here, these three and one are included.

  1. Django
  2. django-grappelli
  3. psycopg2
  4. django-debug-toolbar

Creating a django project

django-admin.py startproject --template https://github.com/sjkingo/django-project-template/archive/master.zip $PROJECT_NAME

The execution was completed easily, and these were completed.

$ ls foo
README.md    manage.py             requirements.txt  urls.py
__init__.py  requirements-dev.txt  settings          wsgi.py

I frozen the pip version and gave manage.py execute permission.

$ cd $PROJECT_NAME
$ pip freeze > requirements.txt
$ rm -f README.md
$ chmod +x manage.py

If you do so far and ./manage.py runserver, you will get a DB error. Because I haven't set it yet. .. ..

Postgresql settings

It's rarely done, so it's always easy to forget.

What is created after installation is Default user: postgres

Postgresql settings in Django, here, I made a note myself.

 systemctl enable postgresql-9.5

Database creation as hoge

postgres=# create database hoge;
CREATE DATABASE
postgres=# \l
postgres=# \l
                              List of databases
Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   

-----------+----------+----------+-------------+-------------+----------------------- hoge | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 rows)

DB user as piyo Create and set password.

$ createuser -a piyo
postgres=# \password piyo
Enter new password: 
Enter it again: 

Set in django settings

Settings such as name in settings / base.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'hoge',
        'USER': 'piyo',
        'PASSWORD': 'piyo',
        'HOST' : '127.0.0.1',
        'PORT' : 5432,
    }
}

Set a simple model.

From the Explosive REST page, set the model and add the management screen settings.

You can now see a slightly grappelli-like management screen.

Screenshot from 2016-05-08 21-29-20.png

First up to here.

Recommended Posts

Take a look at Django's template.
[Go] Take a look at io.Writer
Take a look at profiling and dumping with Dataflow
Take a closer look at the Kaggle / Titanic tutorial
Take a look at the Python built-in exception tree structure
Let's take a look at the feature map of YOLO v3
Take a look at the built-in exception tree structure in Python 3.8.2
Let's take a look at the Scapy code. How are you processing the structure?
[Python] Take a screenshot
Take a peek at the processing of LightGBM Tuner
Challenge image classification by TensorFlow2 + Keras 2 ~ Let's take a closer look at the input data ~
Let's take a quick look at CornerNet, an object detector that does not use anchors.
A quick look at your profile within the django app
Take a screenshot in Python
Try using Django's template feature
[Python] Competitive template [At Coder]
I took a closer look at why Python self is needed
Let's take a look at the forest fire on the west coast of the United States with satellite images.
Let's take a look at the Scapy code. Overload of special methods __div__, __getitem__ and so on.