#Repository creation
mkdir python-django-mvt
cd python-django-mvt
#Create virtualenv
virtualenv env
source env/bin/activate
vi requirements.txt
Django==1.7.1
django-debug-toolbar==1.2.2
MySQL-python==1.2.5
#Required module installation
pip install -r requirements.txt
#Verification
pip freeze
#Project creation
django-admin.py startproject cmsproject
cd cmsproject
vi cmsproject/settings.py
#Change DATABASE setting to mysql, timezone and language to Japan
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cms',
'USER':'user',
'PASSWORD':'password',
'HOST':'127.0.0.1',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'ja'
TIME_ZONE = 'Asia/Tokyo'
#DB initialization
python manage.py migrate
#Create user for Admin
python manage.py createsuperuser
#Server startup
python manage.py runserver
#Management screen access
http://127.0.0.1:8000/admin
python manage.py startapp cms
Now import the project into Intellij
vi cms/models.py
models.py
from django.db import models
# Create your models here.
class Entry(models.Model):
title = models.CharField('title', max_length=255)
contents = models.TextField('contents')
def __str__(self):
return "<Entry('%s', '%s', '%s')>" % (self.id, self.title, self.contents)
Migration
#Add cms to installed app
vi cmsproject/settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cms',
)
#Create migrate file
python manage.py makemigrations cms
#Verification
python manage.py sqlmigrate cms 0001
#Run
python manage.py migrate
python manage.py inspectdb
Github
Recommended Posts