不确定这里是什么问题,但我试图在我的django项目中本地访问我的管理员后端,我收到以下错误:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.4.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in wrapper
213. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
190. if not self.has_permission(request):
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in has_permission
143. return request.user.is_active and request.user.is_staff
File "/Library/Python/2.7/site-packages/django/utils/functional.py" in inner
184. self._setup()
File "/Library/Python/2.7/site-packages/django/utils/functional.py" in _setup
248. self._wrapped = self._setupfunc()
File "/Library/Python/2.7/site-packages/django/contrib/auth/middleware.py" in <lambda>
16. request.user = SimpleLazyObject(lambda: get_user(request))
File "/Library/Python/2.7/site-packages/django/contrib/auth/middleware.py" in get_user
8. request._cached_user = auth.get_user(request)
File "/Library/Python/2.7/site-packages/django/contrib/auth/__init__.py" in get_user
98. user_id = request.session[SESSION_KEY]
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
39. return self._session[key]
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
165. self._session_cache = self.load()
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/db.py" in load
23. self.create()
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/db.py" in create
35. self.save(must_create=True)
File "/Library/Python/2.7/site-packages/django/contrib/sessions/backends/db.py" in save
58. obj.save(force_insert=must_create, using=using)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in insert_query
1576. return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
910. cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py" in execute
40. return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
337. return Database.Cursor.execute(self, query, params)
Exception Type: DatabaseError at /admin/
Exception Value: attempt to write a readonly database
我在openshift上运行这个项目,我的项目目录看起来与此类似:https://github.com/openshift/django-example
知道如何解决这个问题吗?
答案 0 :(得分:1)
这不是python错误;这是你的文件系统的一个问题。您需要检查所有读写权限是否可用。
$ chown Username /path/to/dbfile.db
答案 1 :(得分:1)
cd到该数据库的文件夹并执行
chown www-data:www-data . (apache2 or httpd for non-debian)
chown www-data:www-data <database>
chmod 700 <database>
chmod 755 .
答案 2 :(得分:0)
请谨慎更改@Filip之类的内容:
> django.core.exceptions.ImproperlyConfigured:
> 'django.db.backends.sqlite3' isn't an available database backend. Try
> using 'django.db.backends.XXX', where XXX is one of:
> 'mysql', 'oracle', 'postgresql'