Z
Z
zelsky2015-07-04 17:35:43
Django
zelsky, 2015-07-04 17:35:43

How to fix django url?

The first request when using django-enless-pagination fails. But when you type the identity into the address bar with pens, everything works correctly. Why is that ? And how can anyone fix it?

[04/Jul/2015 14:33:31]"GET /?page=2&querystring_key=page HTTP/1.1" 500 160329
[04/Jul/2015 14:33:42]"GET /?page=2&querystring_key=page HTTP/1.1" 200 6458

from django.conf.urls import include, url
from django.contrib import admin
from endless_pagination.views import AjaxListView

urlpatterns = [
    url(r'^$', 'blog.views.index', name='home'),
    url(r'^add/', 'blog.views.add_post', name='add_post'),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('allauth.urls')),
]

# coding: utf-8
from django.shortcuts import render
from django.http import HttpResponse , HttpResponseRedirect
from django.core.urlresolvers import reverse
from endless_pagination.decorators import page_template
from django.shortcuts import render_to_response
from django.template import RequestContext

from endless_pagination.decorators import page_template
from .models import Posts
@page_template('blog/all_posts.html')  # just add this decorator
def index( request, template='blog/post.html', extra_context=None):
    post = Posts.objects.all()
    context = {'entries':post}
    if extra_context is not None:
        context.update(extra_context)

    return render_to_response(template, context, context_instance=RequestContext(request))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-07-04
@zelsky

[04/Jul/2015 14:33:31]"GET /?page=2&querystring_key=page HTTP/1.1" 500 160329
[04/Jul/2015 14:33:42]"GET /?page=2&querystring_key=page HTTP/1.1" 200 6458

To see the error when returning 500 when sending by Ajax, just look in firebug`e or Google Chrome debugger. If DEBUG = True
The error may be that you are sending a POST request, but waiting for a GET from you. When you initialize the address in the browser, then there you do it with a GET request.
Third:
You are told that request.REQUEST is deprecated and advised to use `request.GET` or `request.POST`. Since it's in the library, try to update it (not always update in the stable public version, check the repository with the latest version).

Z
zelsky, 2015-07-05
@zelsky

The problem was in the templates twice, extends was replaced by include in one MANY THANK YOU
Syschel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question