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,并输入用户名和密码即可

  

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值