日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

django开发Blog(1)

發布時間:2025/7/25 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。