При обращении к сайту выдаёт "DatabaseError at /"
22.11.2013, 06:54. Показов 2111. Ответов 1
Делаю небольшой блог, сидел что то менял месяц назад, и теперь не помню что и не могу найти ошибку 
Код:
Кликните здесь для просмотра всего текста
settings.py
| Python | 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
| # Django settings for SimpleBlog project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'blog.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See [url]https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts[/url]
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# [url]http://en.wikipedia.org/wiki/List_of_tz_zones_by_name[/url]
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'Asia/Novosibirsk'
# Language code for this installation. All choices can be found here:
# [url]http://www.i18nguy.com/unicode/language-identifiers.html[/url]
LANGUAGE_CODE = 'ru-ru'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'a!6a6@rkc@v%$7t%_to7=v4(7p99*nrzm$v35dqlia—z^b&'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'SimpleBlog.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'SimpleBlog.wsgi.application'
import os
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', '../blog/templates').replace('\\','/'),)
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',
'blog',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See [url]http://docs.djangoproject.com/en/dev/topics/logging[/url] for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
} |
|
blog/models.py
| Python | 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
| from django.db import models
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
class Post (models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(unique=True, max_length=255)
create_date = models.DateTimeField(auto_now_add=True)
description = models.CharField(max_length=255)
content = models.TextField()
published = models.BooleanField(default=True)
#author = models.CharField(max_length=30)
class Meta:
ordering = ['-create_date']
def __unicode__(self):
return u'%s' % self.title
def get_absolute_url(self):
return reverse('blog.views.post', args=[self.slug])
# Create your models here.
## Tools---> Run manage.py ---> syncdb |
|
urls.py
| Python | 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
| from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib.auth.views import login, logout
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'SimpleBlog.views.home', name='home'),
# url(r'^SimpleBlog/', include('SimpleBlog.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'blog.views.index'),
url(r'^(?P<slug>[\w\-]+)/$', 'blog.views.post'),
(r'^views.py.login$', 'blog.views.login'),
(r'^views.py.logout$', 'blog.views.logout'),
# (r'^accounts/login/$', 'blog.views.post' ),
# (r'^accounts/profile/$','blog.views.post' ),
#(r'^accounts/logout/$', 'blog.views.post'),
) |
|
blog/views.py
| Python | 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
49
50
51
52
| # coding=utf-8
# Create your views here.
from django.shortcuts import render, get_object_or_404
from blog.models import Post
from django.contrib import auth
from django.http import HttpResponseRedirect
from django.http import HttpResponse
def index(request):
# get the blog posts that are published
posts = Post.objects.filter(published=True)
# now return the rendered template
return render(request, 'index.html', {'posts': posts})
def post(request, slug):
# get the Post object
post = get_object_or_404(Post, slug=slug)
# now return the rendered template
return render(request, 'blog/post.html', {'post': post})
def login(request):
username = request.POST['username']
password = request.POST['password']
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect('/')
else:
return HttpResponse("""
<script language="JavaScript">
<!--
alert("Неправильный логин или пароль!");
window.location.href = "/"
//-->
</script>
""")
def logout(request):
auth.logout(request)
return HttpResponseRedirect("/")
def create(request):
return HttpResponseRedirect("/") |
|
blog/admin.py
| Python | 1
2
3
4
5
6
7
8
9
10
11
| __author__ = 'student'
from django.contrib import admin
from blog.models import Post
admin.site.register(Post) |
|
При обращении к сайту выдает такую ошибку -
| Code | 1
2
| DatabaseError at /
no such table: blog_post |
|
При обращении к админке
| Code | 1
2
| DatabaseError at /admin/
no such table: django_site |
|
Видимо не может найти таблицу, но таблицу я создавал и syncdb делал...
И ещё вопрос - как сделать многопользовательский блог? Чтобы у каждого поста был своей автор и можно было смотреть все посты выбранного автора. Первое что пришло в голову у каждого поста хранить поле "Автор", но как при этом действовать дальше не понятно...
Приложил исходник.
0
|