- 论坛徽章:
- 0
|
1,在ubuntu环境下安装django:
sudo apt-get install python-django
2,安装python mysql相关的支持库文件:
sudo apt-get install mysql-server python-mysqldb
3,开始创建一个django的project:
django-admin startproject mysite
会在mysql目录下面自动生成四个文件:
mysite/ __init__.py manage.py settings.py urls.py
4,首先配置settings.py中数据库相关的设置:(这里使用mysql为列)
修改数据库配置:
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.
修改时区:
TIME_ZONE = 'Asia/Shanghai'
修改系统显示语言:
LANGUAGE_CODE = 'zh-cn'
在INSTALLED_APPS加入后台相关内容:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.admindocs', )
5、同步数据库信息、并添加管理后台用户:
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、设置urls.py开通后台管理访问设置:
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,启动django的web服务:
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 即可登陆管理后台。
管理后台显示中文:
在setting.py中的MIDDLEWARE_CLASSES添加:
'django.middleware.locale.LocaleMiddleware',
9、登陆管理后台提示:
You don't have permission to edit anything.
你无权修改任何东西。
的解决办法:在url.py总取消admin.autodiscover()前面的注释即可!
admin.autodiscover()
|
|