- 論壇徽章:
- 0
|
1,在ubuntu環(huán)境下安裝django:
sudo apt-get install python-django
2,安裝python mysql相關(guān)的支持庫(kù)文件:
sudo apt-get install mysql-server python-mysqldb
3,開(kāi)始創(chuàng)建一個(gè)django的project:
django-admin startproject mysite
會(huì)在mysql目錄下面自動(dòng)生成四個(gè)文件:
mysite/ __init__.py manage.py settings.py urls.py
4,首先配置settings.py中數(shù)據(jù)庫(kù)相關(guān)的設(shè)置:(這里使用mysql為列)
修改數(shù)據(jù)庫(kù)配置:
DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'dbname' # Or path to database file if using sqlite3. DATABASE_USER = 'dbuser' # Not used with sqlite3. DATABASE_PASSWORD = 'password' # Not used with sqlite3. DATABASE_HOST = '127.0.0.1' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '3306' # Set to empty string for default. Not used with sqlite3.
修改時(shí)區(qū):
TIME_ZONE = 'Asia/Shanghai'
修改系統(tǒng)顯示語(yǔ)言:
LANGUAGE_CODE = 'zh-cn'
在INSTALLED_APPS加入后臺(tái)相關(guān)內(nèi)容:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.admindocs', )
5、同步數(shù)據(jù)庫(kù)信息、并添加管理后臺(tái)用戶(hù):
ubuntu:~/mysite$ python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes Username (Leave blank to use 'zhaozhigang'): admin E-mail address: admin@3cc.com.cn Password: Password (again): Superuser created successfully. Installing index for auth.Permission model Installing index for auth.Message model Installing index for admin.LogEntry model
6、設(shè)置urls.py開(kāi)通后臺(tái)管理訪(fǎng)問(wèn)設(shè)置:
ubuntu:~/mysite$ cat urls.py from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin: from django.contrib import admin from mysite.hello import hello from mysite.currtime import * admin.autodiscover()
urlpatterns = patterns('', # Example: # (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)), )
7,啟動(dòng)django的web服務(wù):
ubuntu:~/mysite$ python manage.py runserver 0.0.0.0:8000 Validating models... 0 errors found
Django version 1.1.1, using settings 'mysite.settings' Development server is running at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
[14/Jan/2011 23:23:28] "GET /admin/ HTTP/1.1" 200 1907 [14/Jan/2011 23:24:01] "GET /admin/doc/ HTTP/1.1" 200 2388
8、http://127.0.0.1/admin 即可登陸管理后臺(tái)。
管理后臺(tái)顯示中文:
在setting.py中的MIDDLEWARE_CLASSES添加:
'django.middleware.locale.LocaleMiddleware',
9、登陸管理后臺(tái)提示:
You don't have permission to edit anything.
你無(wú)權(quán)修改任何東西。
的解決辦法:在url.py總?cè)∠鸻dmin.autodiscover()前面的注釋即可!
admin.autodiscover()
|
|