django开发Blog(1)
(一)創(chuàng)建項(xiàng)目
django-admin.py startproject mysite
運(yùn)行這個(gè)命令時(shí),需要django-admin.py在PATH環(huán)境變量中
我的django-admin.py在 Django目錄\Django-1.4.1\django\bin中
此時(shí)目錄結(jié)構(gòu)為
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???????
(二)創(chuàng)建項(xiàng)目blog
manage.py startapp blog
(三)設(shè)置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()
(四)設(shè)置數(shù)據(jù)庫(kù)
???? (1)生成數(shù)據(jù)庫(kù)
???? 我們使用MYSQL,用命令Create Database djangodb;生成數(shù)據(jù)庫(kù)djangodb
(2)設(shè)置配置文件
打開配置文件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
生成表后會(huì)提示是否生成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,并輸入用戶名和密碼即可
轉(zhuǎn)載于:https://www.cnblogs.com/djcsch2001/archive/2012/10/13/2722880.html
總結(jié)
以上是生活随笔為你收集整理的django开发Blog(1)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP教程:WebService最常用的
- 下一篇: 给XCODE加一个注释的小插件