標籤:ret str rate 服務 apply char one tab module
Writing your first Django app, part 1
requriments : Django 1.8 and Python 2.7
建立項目django-admin startproject mysite
.
├── manage.py 命令列呢功能
└── mysite 項目的python包
├── __init__.py 告訴python這個目錄是個python包
├── settings.py 設定檔
├── urls.py 支援的url
└── wsgi.py 相容WSGI的web服務的進入點
更改資料庫在settings檔案中更改DATABASES
建表python manage.py migrate
建立app python manage.py startapp polls
python manage.py sqlmigrate polls 000
sqlmigrate命令實際上並不在資料庫上運行遷移,它只是列印到螢幕上,是用於檢查Django要做什麼。
如果更改了model,即需要更新表
python manage.py makemigrations : create migrations for those changes
python manage.py migrate :apply those changes to the database.
python manage.py shell
manage.py 設定了 DJANGO_SETTINGS_MODULE 環境變數,which gives Django the Python import path to your mysite/settings.py file.
# mysite/polls/models.pyfrom django.db import modelsimport datetimefrom django.utils import timezone# Create your models here.class Question(models.Model): question_text = models.CharField(max_length=200) pub_date = models.DateTimeField(‘date published‘) def __str__(self): return self.question_text def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1)class Choice(models.Model): question = models.ForeignKey(Question) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def __str__(self): return self.choice_text
Writing your first Django app, part 2
Writing your first Django app--2017年5月9日