0

Greetings Django Experts ! I am facing a problem while trying to update data in django template.

I am trying to implement server-side pagination in my django application and for that I am using a single view which contacts a model to fetch data based on the values returned from front end.

For instance : For the first time : No parameters are sent from front-end so returns the first page For the next time : Front-end sends additional data based on which generates new data for rendering

My problem is new data (second time and later on) is not being sent to django template. It still shows the same old data (fetched at the first time) however I m able to print the new_data for context on python console just a step before view returns rendering.

Is there any setting/Django configuration I am missing for rendering new data on same template with same view. I have spent enough time on this problem but fail to find a solution.

View Snippet which do not work for me :

def get_category_records(request):

    # Logic which generates data for result variable

    pprint.pprint(result)
    return render(request, 'SampleApp/category_list.html', {'category' : result })

sample Template SampleApp/category_list.html

<!--{% autoescape off %}-->
{{ category }}
<!--{% endautoescape %}-->

I can see the updates 'result' variable values in django python console BUt the changes are not reflected in django template !!! Setting.py for my porject

"""
Django settings for FalsePositiveProject project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Searching path for django templates
TEMPLATE_DIRS = (os.path.join(BASE_DIR, "FalsePositiveApp/templates/FalsePositiveApp"))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%_d*$-q1ere-2ig!1x0zfq_y&#-n7$6q%m&%)b0a@(p%po)-u^'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'FalsePositiveApp',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'FalsePositiveProject.urls'

WSGI_APPLICATION = 'FalsePositiveProject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        # [AVI] : Leaving blank want to use PyMongo directly
        #'ENGINE': 'django.db.backends.sqlite3',
        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
avimehenwal
  • 1,502
  • 3
  • 21
  • 30
  • Please, show some code – cor Dec 04 '14 at 11:20
  • Hello @cor : I just pasted the code. Kindly let me know if I need to put any other file here – avimehenwal Dec 04 '14 at 11:27
  • 1
    Is it possible that this is caused by client-side caching? [(http://stackoverflow.com/questions/2095520/fighting-client-side-caching-in-django)](http://stackoverflow.com/questions/2095520/fighting-client-side-caching-in-django) If so, try the @never_cache decorator. – JCJS Dec 04 '14 at 11:28
  • I tried using your suggestion. I am afraid to inform that it didn't worked on my system – avimehenwal Dec 04 '14 at 11:52
  • From the code that you have given, everything looks good enough.There is nothing odd.Maybe, you will need to show some more code(both, view and template) to understand the error. – Ymartin Dec 05 '14 at 07:11
  • @Ymartin : I have added setting.py from my project. I have added one TEMPLATE_DIRS variale to it rest all is default. I am still not sure why view is not updaing. Can you help me with how to using server side pagination on Django !!! – avimehenwal Dec 08 '14 at 09:05
  • @AviMehenwal, I have exactly the same problem as yours, I posted a question here before I found your question. Did you solve it? – imdadable Aug 09 '16 at 02:00

0 Answers0