Django notes: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
No edit summary
Line 18: Line 18:
  cd C:\users\david thornton\projects\sc2
  cd C:\users\david thornton\projects\sc2


check that django is installed and owrking
check that django is installed and working


  python -c "import django; print(django.get_version())"
  python -c "import django; print(django.get_version())"
Line 24: Line 24:
make a new project:
make a new project:


  django-admin.py startproject mysite
  django-admin.py startproject sc2
 
Database setup (mysql)
 
edit sc2/settings.py
 
<pre>
DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'sc2',
        'USER': 'sc2user',
        'PASSWORD': 'sc2password',
        'HOST': '127.0.0.1',  # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}
</pre>
 
hydrate app, creates database, both for the app and for various default INSTALLED_APPS:
 
python manage.py migrate
 
this should do a bunch of stuff , including database CREATE work.
 
Start the dev server for the first time:
 
python manage.py runserver
 
alternates:
 
python manage.py runserver 0.0.0.0:8000
 
Create a new app in your porject:
 
python manage.py startapp polls
 
create the model: polls/models.py
 
from django.db import models
 
<pre>
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
 
 
class Choice(models.Model):
    question = models.ForeignKey(Question)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
</pre>

Revision as of 13:55, 18 September 2014

http://dustinfarris.com/2012/09/29/setting-up-a-django-server-with-gentoo.html

the process for tuning the schema:

update the model: scm.py in this case.

python manage.py makemigrations scm
python manage.py sqlmigrate scm 0004
python manage.py migrate scm
python manage.py runserver


Abrdgd Tutorial

go to project dir:

cd C:\users\david thornton\projects\sc2

check that django is installed and working

python -c "import django; print(django.get_version())"

make a new project:

django-admin.py startproject sc2

Database setup (mysql)

edit sc2/settings.py
DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'sc2',
        'USER': 'sc2user',
        'PASSWORD': 'sc2password',
        'HOST': '127.0.0.1',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

hydrate app, creates database, both for the app and for various default INSTALLED_APPS:

python manage.py migrate

this should do a bunch of stuff , including database CREATE work.

Start the dev server for the first time:

python manage.py runserver

alternates:

python manage.py runserver 0.0.0.0:8000

Create a new app in your porject:

python manage.py startapp polls

create the model: polls/models.py

from django.db import models

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)