def index(request):
index = 'index'
comments = Comments.objects.filter(published=True)
paginator = Paginator(comments, 3)
page = request.GET.get('page')
try:
comments = paginator.page(page)
except PageNotAnInteger:
comments = paginator.page(1)
except EmptyPage:
comments = paginator.page(paginator.num_pages)
return render_to_response('index.html', {
'index': index,
'page': page,
'comments': comments})
from django.conf.urls import url, include
from django.contrib import admin
from index.views import index
урл проекта
urlpatterns = [
url(r'^$', index, name='index'),
url(r'^zakaz/', include('contactform.urls') ),
url(r'^admin/', admin.site.urls),
]
from django.conf.urls import url
from contactform.views import contact, thanks
urlpatterns = [
url(r'^contact/', contact, name='contact'),
url(r'^thanks/', thanks, name='thanks'),
]
{% extends 'base.html' %}
{% load staticfiles %}
{% block title %} Обратная связь {% endblock %}
{% block contact %}
<form action="{% url 'contact' %}" method="post">{% csrf_token %}
<div align="center">
{{ form.as_p }}
<input type="submit" value="Отправить!">
</div>
</form>
{% endblock %}
class Subscribe(models.Model):
class Meta:
db_table = 'subscribe'
subscriber = models.ForeignKey(User)
post = models.ForeignKey(Post)
sub_date = models.DateTimeField(auto_now_add=True)
class Post(models.Model):
class Meta:
db_table = 'post_app'
verbose_name = 'Публикация'
verbose_name_plural = 'Публикации'
autor = models.ForeignKey('auth.User', verbose_name='Автор')
post_name = models.CharField(max_length=100, verbose_name='Заголовок')
post_text = models.TextField(verbose_name='Текст')
post_created_date = models.DateTimeField(default=timezone.now, verbose_name='Дата')
post_datetime = models.DateTimeField(blank=True, null=True, verbose_name='Дата публикации')
class Post(models.Model):
class Meta:
db_table = 'post_app'
verbose_name = 'Публикация'
verbose_name_plural = 'Публикации'
autor = models.ForeignKey('auth.User', verbose_name='Автор')
post_name = models.CharField(max_length=100, verbose_name='Заголовок')
post_text = models.TextField(verbose_name='Текст')
post_created_date = models.DateTimeField(default=timezone.now, verbose_name='Дата')
post_datetime = models.DateTimeField(blank=True, null=True, verbose_name='Дата публикации')
def publich(self): # Функция даты публикации должна соответствовать временной зоне
self.post_created_date = timezone.now() # Параметр timezone.now() говорит о том, что пользователь будет сохранять статьи в текущем времени публикации.
self.save()
def __unicode__(self):
return self.post_name
class Comments(models.Model):
class Meta:
db_table = 'comments'
ordering = ['-comments_date']
verbose_name = 'Комментарий'
verbose_name_plural = 'Комментарии'
comments_post = models.ForeignKey(Post, verbose_name='Статья')
comments_text = models.TextField(verbose_name='Текст')
comments_date = models.DateTimeField(auto_now=True, null=True, verbose_name='Дата')
comments_autor = models.ForeignKey('auth.User', verbose_name='Автор')
да ошибка ушла, но ссылки на фейсбук нет