Заработало!Сделал следующее:В view.py подключил from django.template import RequestContextИ переписал def articles_insideПолучилось следующее:
from django.core.context_processors import csrf
from django.template import RequestContext
....
def articles_inside(request, articles_id):
art_id = int(articles_id)-1
article = Articles.objects.all()[art_id]
return render_to_response('articles_inside.html', {'article':article, 'art_id': art_id+1}, context_instance=RequestContext(request))
blackslash Добрый день.Второй день вожусь с ошибкой CSRF verification failed. Request aborted.При клике Post или Preview выводит ошибку 403 CSRF verification failed. Request aborted.models.py
class BlogPost(models.Model):
title = models.CharField(max_length=150)
short_body = models.TextField()
body = models.TextField()
timestamp = models.DateTimeField()
logo = models.ImageField(upload_to="static/")
class Meta:
ordering = ("-timestamp",)
class BlogPostAdmin(admin.ModelAdmin):
list_display = ("id", "title", "timestamp")
admin.site.register(BlogPost, BlogPostAdmin)
article_inside.html
{% for b in article.sections.all %}
{{ b.name }}
{% endfor %}
{{ article.title }}
{{ article.publication_date}}
{% if article.picture %}
{% endif %}
{{ article.text|safe }}
{% load comments %}
{% get_comment_count for article as comment_count %}
{% get_comment_list for article as comment_list %}
{% get_comment_count for article as comment_count %}
This event has {{ comment_count }} comments.
{% get_comment_form for article as form %}
{% csrf_token %}
{{ form }}
url.py
url(r"^archive/", archive),
(r'^comments/', include('django.contrib.comments.urls')),
view.py
from django.core.context_processors import csrf
...
def archive(request):
posts = BlogPost.objects.all()
t = loader.get_template("archive.html")
c = Context({"posts": posts })
c.update(csrf(request))
return HttpResponse(t.render(c))
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'grappelli',
'filebrowser',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.comments',
'myproject.blogs',
)
....
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
)