I ran into this problem for quite some time and is having trouble solving this. Right now I am using django 1.2.4 and having the following settings:
AUTH_PROFILE_MODULE = 'customUsers.UserProfile'
TEMPLATE_STRING_IF_INVALID = 'Error generating variable'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ANONYMOUS_USER_ID = -1
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
'guardian.backends.ObjectPermissionBackend',
)
MANAGERS = ADMINS
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
# "django.core.context_processors.static", there is no this function in the file
"django.contrib.messages.context_processors.messages",
"customUsers.user_cp_context.userCPContext")
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/Users/carrier24sg/Documents/workspace/static_teachers/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '(grqejktuccy6!#5pr#535*vivl#lcv06=v*hvae#&6mx15nzt'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
#ROOT_URLCONF = 'myproject.urls'
#TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# '/home/carrier24sg/webapps/django/myproject/templates'
#)
SITE_ID = 2
ROOT_URLCONF = 'teachers.urls'
TEMPLATE_DIRS = (
'/Users/carrier24sg/Documents/workspace/templates',
'/Users/carrier24sg/Documents/workspace/teachers/templates'
)
INSTALLED_APPS = (
'customUsers',
'ConsentForm',
'teachers.consent_teachers',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'conversation',
'teachers.student_profiling',
'south',
'guardian',
'persistent_messages',)
For some reasons I cannot serve static files like js and css. The output of the development server displays 404 error "GET /media/common/css/sidebar.css HTTP/1.1" 404 2202 I have tried entering the url for the static file on browser, instead of telling me that the file cannot be found(which i was expecting), I was shown the url-unmatched django debug page Using the URLconf defined in teachers.urls, Django tried these URL patterns, in this order: ......The current URL, media/js/conversation_load.js, didn't match any of these.
Question: why is django not reading the url http://127.0.0.1:8000/media/js/conversation_load.js like a request for static file?
for example, you have your "media" folder near settings.py
Then try:
from os import path
MEDIA_ROOT = path.join(path.dirname(__file__), 'media')
Where "media" is you media folder name.
In urls.py:
from os import path
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': path.join(path.dirname(__file__), 'media')}),
Have you added into your templates:
{% load staticfiles %}
This loads what's needed.
Related
I wanted to include an ecommerce portal on my website and I have done everything as given on the "Create your Shop page" as given in Django-Oscar documentation, just that in
urls.py instead of
url(r'', include(application.urls)),
I have added
url(r'^buy/', include(application.urls)),
but the problem is that when I hit the url it is neither showing anything nor giving an error.
Any idea what could be the problem?
It could be some urls are clashing or something else trivial but I am not able to understand from where to start debugging.
File urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from view import AboutusView, TwentySevenView
import apps.users.views
from django.conf import settings
#oscar urls
from oscar.app import application
admin.site.site_header = ''
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'torquehp.views.home', name='home'),
# url(r'^users/', include('users.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^admin/', include(admin.site.urls)),
url(r'^about-us/$', AboutusView.as_view(), name="about-us"),
url(r'^24x7/$', TwentySevenView.as_view(), name="24x7"),
url(r'^$', apps.users.views.user_home, name="home"),
url(r'^markdown/', include('django_markdown.urls')),
url(r'^users/', include('apps.users.urls')),
url(r'^doorstep/', include('apps.doorstep.urls')),
url(r'^cars/', include('apps.cars.urls')),
url('', include('social.apps.django_app.urls', namespace='social')),
# urls for zinnia
url(r'^blog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django_comments.urls')),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, }),
# oscar URLs
url(r'^buy/', include(application.urls)),
)
File settings.py
import os
import sys
from oscar import get_core_apps
from oscar import OSCAR_MAIN_TEMPLATE_DIR
from oscar.defaults import *
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
location = lambda x: os.path.join(
os.path.dirname(os.path.realpath(__file__)), x)
# sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) # to store apps in apps/ directory
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'apps.users',
'apps.doorstep',
'apps.cars',
'django_markdown',
'social.apps.django_app.default',
'django.contrib.sites',
'django_comments',
'mptt',
'tagging',
'zinnia',
'compressor',
] + get_core_apps()
# specifying the comments app
# COMMENTS_APP = 'zinnia_threaded_comments'
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'oscar.apps.basket.middleware.BasketMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)
# Authentication backend used by python-social-auth
AUTHENTICATION_BACKENDS = (
'social.backends.facebook.FacebookOAuth2',
'social.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
'oscar.apps.customer.auth_backends.EmailBackend',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"social.apps.django_app.context_processors.backends",
"social.apps.django_app.context_processors.login_redirect",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.i18n",
"django.core.context_processors.request",
"zinnia.context_processors.version",
"django.core.context_processors.debug",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
'oscar.apps.search.context_processors.search_form',
'oscar.apps.promotions.context_processors.promotions',
'oscar.apps.checkout.context_processors.checkout',
'oscar.apps.customer.notifications.context_processors.notifications',
'oscar.core.context_processors.metadata'
)
# TEMPLATE_LOADERS = (
# 'app_namespace.Loader',
# )
ROOT_URLCONF = 'torquehp.urls'
WSGI_APPLICATION = 'torquehp.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "",
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306'
}
}
# Internationalization
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOGIN_URL = '/users/login/'
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/static/')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = "/media/"
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates').replace('\\', '/'),
location('templates'),
OSCAR_MAIN_TEMPLATE_DIR,
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'staticfiles'),
)
REGISTRATION_INVALID = 50
MESSAGE_TAGS = {
REGISTRATION_INVALID: 'InvalidDetails',
}
# temporary , should not be in settings file
SOCIAL_AUTH_FACEBOOK_KEY = ""
SOCIAL_AUTH_FACEBOOK_SECRET = ""
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = ""
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = ""
LOGIN_REDIRECT_URL = '/blog/'
# ------------------------------------ #
# Settings for sending email #
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# ------------------------------------ #
# site id for django sites framework
SITE_ID = 1
# configuration settings for django-zinnia
ZINNIA_PING_EXTERNAL_URLS = False
ZINNIA_SAVE_PING_DIRECTORIES = False
ZINNIA_MARKUP_LANGUAGE = 'markdown'
ZINNIA_UPLOAD_TO = 'uploads/zinnia/'
# TimeZone Settings
USE_TZ = True
# ------------------------ #
# django s=oscar search settings
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
}
Screenshots:
http://localhost:8000/buy/
http://localhost:8000/buy/catalogue/
I see that in your second screenshot localhost:8000/buy/catalogue/ you actually get a result. It would seem as if you haven't defined your own templates or somehow need to fix your TEMPLATE_DIRS or TEMPLATE_CONTEXT_PROCESSORS settings.
I haven't used oscar, but that fact that you get something on screen seems like a template loading issue to me.
See their docs about setting the template_context_processors
Can you post your settings please?
Update:
After seeing your settings, the template_context_processors look correct. I next looked at oscar's templates and they seem to extend without qualifying the oscar directory. For example, layout.html (/oscar/templates/oscar/layout.html) does this:
{% extends 'base.html' %}
Now, if you also have a 'base.html' file in your own project directory, say project_dir/templates/base.html, then it'll probably use that instead. Can you try to temporarily rename that file (if it exists) and see what happens?
urls.py
url(r'^buy/', include("app.urls")),
Then under your app directory create a file called urls.py
app/urls.py
# this is your “http://localhost:8000/buy/”
url(r'^$', ViewName.as_view(), name="thename"),
In app/urls.py add the following line:
url(r'^$',views.index,name='index'),
This will redirect you to the index function in app/views.py
In app/views.py do something like that:
def index(request):
#Your logic here
return render(request,'urpoll/index.html'{'category':categorys,'ques':ques,'url':url})
This will render index.html with categories,ques,url. In index.HTML so something like that:
{{ if category }}
{{ category }}
{{ endif }}
I hope this will help.
Maybe you have a naming collision with templates. Django's default template loader, which I assume you're using, can be a bit unintuitive. When you ask it for a template with a given name, it goes through your INSTALLED_APPS tuple in settings in order, checking in each one for a templates folder. If there are two templates with the same path in two different apps, it will always take the first one it finds.
That's why the recommendation in django docs is to 'namespace' your templates by keeping them all in another folder with the name of your app, within the templates folder. Oscar does this, so their templates are in oscar/templates/oscar, so they shouldn't be colliding with any other apps, but I'm wondering if maybe you put an 'oscar' folder within the templates of one of your apps, possibly clashing with base.html.
The problem is that django-oscar is not meant to be included under a sub-path, such as /buy/. In their documentation, their example shows installing it as:
url(r'', include(application.urls)),
If you look at the source of get_urls(), which provides the return value for application.urls, you can see that it does not provide a urlpattern to match r'^$', which is what you would need to match at the URL you are trying to view.
In short, you should follow exactly what the documentation recommends, or you will get unexpected results.
All, i am using Django1.4,i have a question regarding accessing the img files,js files etc... I have my files in the directory /opt/lab/labsite/media/img for images and /opt/lab/labsite/media/js for javascript files.What should i change the settings in the setting files such that the below html works..I am using django server to run the code
My code is currently located in /opt/lab/labsite/settings.py and other modules lies in /opt/lab/labsite/.........
<img src="/media/img/logo.jpg" alt="logo" />
Below are the settings in the settings.py file
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/opt/lab/labsite/media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/opt/lab/labsite/media/'
Changes
MEDIA_ROOT = '/opt/lab/labsite/media/'
MEDIA_URL = '/media/'
STATIC_ROOT = '/opt/lab/labsite/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'labsite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'labssite.wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/opt/lab/labsite/templates'
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'home',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth'
)
HTML:
<img src="{{ STATIC_URL }}img/hi.png" alt="Hi!" />
<img src="/static/img/hi.png" alt="Hi!" />
<img src="/media/img/hi.png" alt="Hi!" />
<img alt="Hi!" src="/opt/ilabs/ilabs_site/media/img/hi.png">
STATIC_URL you have set doesn't look good. I think that should be STATIC_ROOT.
You should set (for example) MEDIA_URL='/media/' and STATIC_URL='/static/' and I hope you have also enabled static file serving in urls.py
Set this in settings.py:
STATIC_ROOT = '/opt/html/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/opt/lab/labsite/static/',
)
add this in context processors:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'django.core.context_processors.static',
...
)
and don't forget this in INSTALLED_APPS:
'django.contrib.staticfiles',
and then:
<img src="/static/img/logo.jpg" alt="logo" />
or
<img src="{{ STATIC_URL}}img/logo.jpg" alt="logo" />
if logo.jpg is located in /opt/lab/labsite/static/img/
In addition, STATIC_ROOT serves as a static folder to be served by Web servers/reverse proxies like Apache, Nginx, etc. If you invoke:
python manage.py collectstatic
This will copy all files from /opt/lab/labsite/static/ to STATIC_ROOT - /opt/html/static/. This is useful for deployments.
But all this is for development. For production there are better ways to serve static content - https://docs.djangoproject.com/en/dev/howto/static-files/#staticfiles-production
I have stopped creating new project with django 1.1 and from that time was only working on already created applications. Since then I guess that static serving somehow changed (project is using Django 1.2.4). I'm struggling for few hours and with no results, so if somebody knows what I'm doing wrong please let me know.
My settings :
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
MEDIA_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'
SECRET_KEY = '(d9bahjuyy_i-)4b(w9gc5a&s&5jemcn7&b^wrbuemah3p-6^#'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.admindocs',
'project',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.media",
"django.core.context_processors.csrf",
"django.core.context_processors.i18n",
)
urls:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes' : True}),
)
And media files are located in ../project_path/media
In templates I get the {{ MEDIA_URL }} path as /static/ but my files are not loaded. Going to http://127.0.0.1:8000/static/ (with or without last slash) shows root page. Firebug shows the html code of page in place of javascript files. I would rather expect 404 error. Where's the problem ?
Swicthed to 1.3 . Problem remains.
Just in case if you are using render_to_response, you have to pass optional 3rd parameter:
context_instance=RequestContext(request)
soe the full code looks like:
return render_to_response('index.html',{'dict':'ionary'},context_instance=RequestContext(request))
{{ STATIC_URL }} works with RequestContext, while default for render_to_response is Context
If you are using Django's 1.3 django.contrib.staticfiles, the app will look for static files under the static sub-folder of all your installed apps. For instance, staticfiles will automatically pick up the following css:
yourproject/
appone/
static/
sample.css
If you are using django.contrib.staticfiles and STATIC_URL = '/static/' in your settings.py, you can easily access the css at:
http://localhost:8000/static/sample.css
For your case, it looks like you have a static folder under your project folder, I will assume the following:
yourproject/
static/
If you want staticfiles to pick the above, remove the following from urls.py:
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes' : True}),
Add the following to your settings.py:
import os
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'static'),
)
In your template, you might want to start using STATIC_URL instead of MEDIA_URL unless they are both pointing to the same value.
You can read more about staticfiles in Django 1.3.
I have been wrangling with Django for some weeks now, putting it down, picking it up, and now I am convinced that it's what I want to use. I got a site up and running with django-cms, but have a small challenge with cmsplugin-news.
I can input news items, list latest news items, and all works fine. However, when I click on an individual news item to view the detail, I get a 404 page not found error.
Here is my urls.py and settings.py file, respectively.
URLS.PY
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
url(r'^news/', include('cmsplugin_news.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
SETTINGS.PY
# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
LANGUAGES = [('en', 'en'),('jp','jp')]
DEFAULT_LANGUAGE = 0
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_DIR, 'anadacms.db'),
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = "http://portal.workpapers.pro/media/"
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/admin/media/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'MYSECRETKEY'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'cms.context_processors.media',
)
CMS_TEMPLATES = (
('example.html', 'Basic Template'),
('template_1.html', 'Template One'),
('template_2.html', 'Template Two'),
)
ROOT_URLCONF = 'urls'
CMS_APPLICATIONS_URLS = (
('cmsplugin_news.urls', 'News'),
)
CMS_NAVIGATION_EXTENDERS = (
('cmsplugin_news.navigation.get_nodes', 'News navigation'),
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'cms',
'menus',
'mptt',
'appmedia',
'south',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.snippet',
'cms.plugins.googlemap',
'publisher',
'cms.plugins.teaser',
'cms.plugins.video',
'cms.plugins.twitter',
'cmsplugin_facebook',
'cmsplugin_news',
)
Here is a link to the urls.py file for the cmsplugin-news app:
https://bitbucket.org/MrOxiMoron/cmsplugin-news/src/03ba1b86624b/cmsplugin_news/urls.py
The problem is very simple: The cms.urls should always be last in your urlconf because it eats every request.
Changing your urls.py to this should fix it::
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^news/', include('cmsplugin_news.urls')),
# MUST BE LAST!!!
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
I'm trying to get django cms' plugin context processors for my hooked app. I followed the documentation http://docs.django-cms.org/en/2.1.3/extending_cms/custom_plugins.html#plugin-context-processors , but for some reason it doesn't work. Here is a my sample context processor:
def test_context_processor(instance, placeholder):
print instance
return {'testkey':'testvalue'}
and my template:
{% load cms_tags %}
<!doctype html>
<head>
<title></title>
{% plugins_media %}
</head>
<body>
{% placeholder "main" %}
</body>
</html>
I added a text plugin in the main placeholder, and added the text {{testkey}}. It renders it as {{testkey}} instead of testvalue. The print statement in the context processor gets logged properly - meaning that the context processor is called for sure. I'm not sure what am I doing wrong here.
--- Edit ---
My settings file:
# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
LANGUAGES = [('en', 'en')]
DEFAULT_LANGUAGE = 0
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(PROJECT_DIR, 'mycms.db'),
# }
#}
DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = '***' # Or path to database file if using sqlite3.
DATABASE_USER = '***' # Not used with sqlite3.
DATABASE_PASSWORD = '***' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '5432' # Set to empty string for default. Not used with sqlite3.
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '0r6%7gip5tmez*vygfv+u14h#4lbt^8e2^26o#5_f_#b7%cm)u'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'cms.context_processors.media',
)
CMS_PLUGIN_CONTEXT_PROCESSORS = (
'helpdocs.cms_context_processors.test_context_processor',
)
CMS_TEMPLATES = (
('example.html', 'Example Template'),
)
ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'cms',
'menus',
'mptt',
'appmedia',
'south',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.snippet',
'cms.plugins.googlemap',
'helpdocs',
)
The Plugin Context Processors are used to process the context with which the templates of the plugin are rendered. They do not alter the content of any database field (in your case, 'body' on the Text model).
Therefore it will not replace anything in your text plugin. To do what you're trying to do, have a look at Plugin Processors (http://docs.django-cms.org/en/2.1.3/extending_cms/custom_plugins.html#plugin-processors) which allow you to process the rendered output of a plugin.
To achieve what you're trying to do you would do something like this:
def my_plugin_processor(instance, placeholder, rendered_content, original_context):
return rendered_content.replace('{{ testkey }}', 'testvalue')