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/'