接上篇文章《ImportError: No module named setuptools》,配置完成django后,开始尝试配置django:
0 1 2 3 |
[root@hz site]# /byrd/server/Python-2.7.7/bin/django-admin.py startproject django CommandError: 'django' conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name. [root@hz site]# /byrd/server/Python-2.7.7/bin/django-admin.py startproject first [root@hz site]# python manage.py runserver 0.0.0.0:8080 |
数据库问题报错:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[root@hz site]# python manage.py runserver 0.0.0.0:8080 Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute translation.activate('en-us') File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate return _trans.activate(language) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate _active.value = translation(language) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation default_translation = _fetch(settings.LANGUAGE_CODE) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch app = import_module(appname) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 6, in <module> from django.contrib.admin.sites import AdminSite, site File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 4, in <module> from django.contrib.admin.forms import AdminAuthenticationForm File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/contrib/admin/forms.py", line 6, in <module> from django.contrib.auth.forms import AuthenticationForm File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 17, in <module> from django.contrib.auth.models import User File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/contrib/auth/models.py", line 48, in <module> class Permission(models.Model): File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/models/base.py", line 96, in __new__ new_class.add_to_class('_meta', Options(meta, **kwargs)) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/models/base.py", line 264, in add_to_class value.contribute_to_class(cls, name) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/models/options.py", line 124, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/utils.py", line 198, in __getitem__ backend = load_backend(db['ENGINE']) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/utils.py", line 113, in load_backend return import_module('%s.base' % backend_name) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/byrd/server/Python-2.7.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 35, in <module> raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc) django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3 |
增加MySQL数据库:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@hz first]# cd first/ mysql> create database dj default character set utf8 collate utf8_general_ci; mysql> create user 'dj'@'localhost' identified by 'admin'; mysql> grant all on dj.* to 'dj'@'localhost' identified by 'admin'; mysql> quit [root@hz first]# vim settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'dj'), 'USER': 'dj', 'PASSWORD': 'admin', 'HOST': '127.0.0.1', 'PORT': '3306', } } [root@hz first]# vim first/settings.py [root@hz first]# python manage.py shell Python 2.7.7 (default, Jun 26 2014, 20:29:16) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.db import connection >>> cursor = connection.cursor() [root@hz first]# python manage.py runserver #ctrl+c [root@hz first]# python manage.py runserver 0.0.0.0:8000 |
参考:http://www.cnblogs.com/fnng/p/3737964.html
参考:http://blog.csdn.net/sunbaigui/article/details/6637312
参考:http://blog.csdn.net/robinliu2010/article/details/7643530
参考:http://blog.csdn.net/chenggong2dm/article/details/17394439
参考:http://www.cnblogs.com/searchappiness/archive/2013/05/07/3064044.html SourceByrd's Weblog-https://note.t4x.org/environment/django-mysql-database/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!