我是python和django的新手,最近我遇到了一些问题。 Django-admin.py runserver不起作用(ubuntu 12.04)。
终端错误代码:
linas@ubuntu:~$ django-admin.py runserver
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/usr/local/lib/python2.7/dist-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
感谢您的帮助。
编辑: 这是我使用./manage.py runserver
时得到的linas@ubuntu:~/Dokumentai/python/FirstBlog$ ./manage.py runserver
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1148c90>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 411, in get_server_version
self.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1049, "Unknown database 'FirstBlog'")
答案 0 :(得分:7)
使用项目目录中的manage.py
cd project
./manage.py runserver
答案 1 :(得分:0)
你可以发布你的模特吗?你也创建了数据库吗?
运行:
python manage.py syncdb
答案 2 :(得分:0)
首先(我希望你已经这样做)创建一个带有项目名称的目录,然后启动执行命令的django项目: python django-admin.py startproject projname (如果没有正确执行,请删除关键字“python”并尝试) 现在从同一目录运行python manage.py runserver。如果您已正确安装,您将获得: 验证模型 。 。 找到0个错误