Centos6.5 (IP:192.168.1.155) python 2.6 django 1.5
yum install python-devel mysql-devel zlib-devel openssl-devel mysql mysql-server zlib zlib-devel
[root@localhost Django-1.5.12]# cd /usr/local/ [root@localhost local]# django-admin.py startproject mysite [root@localhost local]# tree mysite/ mysite/ ├── manage.py └── mysite ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py
1 directory, 5 files [root@localhost local]#
[root@localhost local]# cd mysite/ [root@localhost mysite]# python manage.py runserver 0.0.0.0:8000 Validating models...
0 errors found January 31, 2015 - 13:55:28 Django version 1.5.12, using settings 'mysite.settings' Development server is running at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
ok到此,我们的工程创建成功
[root@localhost zdong]# pip install django-reversion
[root@localhost zdong]# pip install MySQL-python
[root@localhost zdong]# pip install django-xadmin
Collecting django-xadmin Downloading django-xadmin-0.5.0.tar.gz (1.0MB) 100% |################################| 1.0MB 224kB/s /tmp/pip-build-FlsY1Q/django-xadmin/setup.py:12: DeprecationWarning:
[root@localhost zdong]# cd /usr/local/mysite/mysite/
[root@localhost mysite]# ls __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc
在settings.py 中修改如下信息 #配置你的数据库连接信息
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'xadmin', # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': 'zdong', 'PASSWORD': '123456', 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '', # Set to empty string for default. } }
#APPS 中添加xadmin的信息
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', ############################ 'xadmin', 'crispy_forms', 'reversion', ############################
urls.py配置如下
from django.conf.urls import patterns, include, url import xadmin xadmin.autodiscover() from xadmin.plugins import xversion xversion.register_models() urlpatterns = patterns('', url(r'^xadmin/', include(xadmin.site.urls), name='xadmin'), )
[root@localhost mysite]# mysql Welcome to the MySQL monitor. Commands end with ; or g. mysql> create database xadmin; Query OK, 1 row affected (0.00 sec) mysql> grant all on xadmin.* to 'zdong'@'127.0.0.1' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
[root@localhost mysite]# python manage.py collectstatic AttributeError: 'module' object has no attribute 'atomic' [root@localhost mysite]# 看到这个问题,我纠结了好久,一直寻找不到解决的办法,后来就直接改xadmin的代码了,注释了atomic的信息。
解决办法(不建议使用,希望能找到更好的办法)
vim /usr/lib/python2.6/site-packages/reversion/admin.py 文件中 atomic的信息 384 # @transaction.atomic 385 # def recover_view(self, request, version_id, extra_context=None): 386 # """Displays a form that can recover a deleted model.""" 387 # # check if user has change or add permissions for model 388 # if not self.has_change_permission(request) and not self.has_add_permission(request): 389 # raise PermissionDenied 390 # version = get_object_or_404(Version, pk=version_id) 391 # obj = version.object_version.object 392 # context = {"title": _("Recover %(name)s") % {"name": version.object_repr},} 393 # context.update(extra_context or {}) 394 # return self.render_revision_form(request, obj, version, context, recover=True) 395 396 # @transaction.atomic
在次收集media的信息
[root@localhost mysite]# python manage.py collectstatic
You have requested to collect static files at the destination location as specified in your settings.
This will overwrite existing files! Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
ok成功了
root@localhost mysite]# python manage.py syncdb Creating tables ... Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_groups Creating table auth_user_user_permissions Creating table auth_user Creating table django_content_type Creating table django_session Creating table django_site Creating table reversion_revision Creating table reversion_version Creating table xadmin_bookmark Creating table xadmin_usersettings Creating table xadmin_userwidget
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 'root'): admin #用户名是登陆后台的用户名 Email address: 123456@qq.com Password: #登陆后台的密码 Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s) [root@localhost mysite]#
[root@localhost mysite]# python manage.py runserver 0.0.0.0:8000
OK到此结束,希望这篇文章能帮你节省安装所花费的时间。
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞2
添加新评论0 条评论