[PYTHON] Django initial setup up to Intellij Debug

environment

Initial setting

#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

Create Django Project (using MySQL)

#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

Django App Creation

python manage.py startapp cms

Intellij settings

Now import the project into Intellij

Model added

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

If the table already exists

python manage.py inspectdb

Github

reference

Recommended Posts

Django initial setup up to Intellij Debug
How to do the initial setup from Django project creation
[Django] Give an initial value to ChoiceField
How to print debug messages to the Django console
How to debug selenium
unable to import django
update django version 1.11.1 to 2.2
Try Fortran with VS Code up to debug settings. [Win10]