django开发Blog(1)
(一)創建項目
django-admin.py startproject mysite
運行這個命令時,需要django-admin.py在PATH環境變量中
我的django-admin.py在 Django目錄\Django-1.4.1\django\bin中
此時目錄結構為
mysite
│? manage.py
│?
├─blog
│????? models.py
│????? tests.py
│????? views.py
│????? __init__.py
│?????
└─mysite
??????? settings.py
??????? settings.pyc
??????? urls.py
??????? urls.pyc
??????? wsgi.py
??????? wsgi.pyc
??????? __init__.py
??????? __init__.pyc???????
(二)創建項目blog
manage.py startapp blog
(三)設置model
找到models.py
from django.db import models
#Create your models here
刪掉注釋,加入以下代碼
class BlogPost(model.Model):
??? title=models.CharField(max_length=150)
??? body=models.TextField()
??? timestamp=models.DateTimeField()
(四)設置數據庫
???? (1)生成數據庫
???? 我們使用MYSQL,用命令Create Database djangodb;生成數據庫djangodb
(2)設置配置文件
打開配置文件setting.py,找到DATABASES ={...},改成
DATABASES = {
??? 'default': {
??????? ?'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
???????? 'NAME': 'djangodb',????????????????????? # Or path to database file if using sqlite3.
??????? ?'USER': 'root',????????????????????? # Not used with sqlite3.
??????? ?'PASSWORD': 'djcsch2001',????????????????? # Not used with sqlite3.
???????? 'HOST': 'localhost',????????????????????? # Set to empty string for localhost. Not used with sqlite3.
??????? ?'PORT': '',????????????????????? # Set to empty string for default. Not used with sqlite3.
???? ?? }
???? }
(3)生成表
manage.py syncdb
生成表后會提示是否生成admin賬戶:
You just installed Django's auth system,which means you don't hava any superusers definde.
Would you like to create one now?(yes/no):yes?
選擇yes,并輸入用戶名和密碼即可
轉載于:https://www.cnblogs.com/djcsch2001/archive/2012/10/13/2722880.html
總結
以上是生活随笔為你收集整理的django开发Blog(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP教程:WebService最常用的
- 下一篇: 给XCODE加一个注释的小插件