django flatpages aren't working - django

My flatpages relevant options in the settings.py look like this:
MIDDLEWARE_CLASSES = (
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.flatpages',
'django.contrib.humanize',
'registration',
)
and in the Backend I added a flatpage with the url set to "/" and one with "/about/. When I call these pages, django shows a 404 error. All my flatpages have a unique template. The "Template Name" entries are looking like this: /flatpages/about.html. What did i miss?

I found it.
I forgot to set the SITE_ID in settings.py correctly.

Do you have a base/default template in place for your flatpages, too? It's easy to miss as they docs don't go into much detail.
Easiest fix is to add /flatpages/default.html to your known templates, basing default.html on the example in the docs.
Or you can point your flatpages to a specific, existing template with the additional options in the admin edit page for a flatpage.

The key statement is changing the SITE_ID in settings.py which
has nothing to do with flatpages - it is a problem that new users
run into when launching into the 'admin' and adding (say) '127..0.0.1' to
the sites menu ( an addition to the default 'example.com' )
In trying to get everything else right, it is easy to overlook
making SITE_ID = 2.
Make 'locahost' the default - get rid of the default tripwire.
Glad I came across this!
Bob

Related

Hide app in django admin panel

I have django-admin-interface installed in my django app. I configured layout using this plugin and I would like to hide it from admin panel. My goal is to store basic settings in database. Is it possible?
I can't find any relations in my code to this plugin. There is only one place in my code (settings.py) where phrase admin_interface appears.
INSTALLED_APPS = [
'mainapp.apps.MainappConfig',
'admin_interface',
'colorfield',
'flat_responsive',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'smart_selects',
'activatable_model',
'bootstrap3',
'mainapp.apps.ConstanceConfig',
'constance.backends.database',
'kronos',
'ckeditor',
'django_admin_listfilter_dropdown',
]
Is is possible to hide this area in admin panel?
You can use unregister in your admin.py.
from django.contrib import admin
from admin_interface.models import Theme
admin.site.unregister(Theme)
Note:
If you have multiple apps and hence multiple admin.py, then adding this snippet in anyone of them will hide the app

Unable to minify html files using django-pipeline

In accordance with the django-pipeline docs, I've added 'pipeline.middleware.MinifyHTMLMiddleware', to my MIDDLEWARE_CLASSES to minify html files. But, when I check the htmls that have been rendered while running the server, they are not minified. Can some one please suggest if I am missing anything.
Below are my MIDDLEWARE_CLASSES. I even tried with GZipMiddleware class enabled, but it still does'nt work. I have also tried with both DEBUG = False & DEBUG = True in settings.py with no success.
MIDDLEWARE_CLASSES = (
#'django.middleware.gzip.GZipMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'Testapp.signin.views.SocialAuthExceptionMiddleware',
)
EDIT: Added Installed Apps and Static files storage settings.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#'django.contrib.admin',
'social.apps.django_app.default',
# 'django.contrib.admindocs',
'Testapp',
'signin',
'pipeline',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
To work pipeline MinifyHTMLMiddleware change DEBUG = False in settings.py
DEBUG = false
Or add in settings.py
PIPELINE_ENABLED = True
i've had the same issue, but I've found the solution. You have to add this Middleware class first:
'htmlmin.middleware.MarkRequestMiddleware',
When you do that it adds to request an attribute
request._hit_htmlmin = True
which is checked then in MinifyHTMLMiddleware class. Now it's working great.

Django Immediently expiring sessions

I'm experiencing an issue with Django and Django Auth. From time to time the login page will not allow users to login. When the user presses login (on the /admin login form OR any custom login form) the page simply refreshes. After debugging further it seems that it is creating a session and then expiring it (somehow). Has anyone experienced this type of behavior with Django Auth?
Thanks,
cory
I haven't had this problem.
But so, you should check your apps, middleware, and context processor specifications in your settings.py file. You'll want to be sure the following are in place (in addition to whatever else you need for your specific app):
MIDDLEWARE_CLASSES = (
# ...
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# ...
)
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
"django.core.context_processors.auth",
"django.core.context_processors.request",
# ...
)
INSTALLED_APPS = (
# ...
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
# ...
)
... make sure that's all good to go and see if your problem persists. Good luck.

Django sessions is not working

i'm trying to find bug for few hours now but nothing comes out.
Django gives me this error message when i'm trying to access request.SESSION from view. No other errors.
'WSGIRequest' object has no attribute 'SESSION'
Here is my Django settings what points to sessions and authentication. Most of them are set to their defaults.
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
AUTH_PROFILE_MODULE = 'alkimikis.users.models.UserProfile'
INSTALLED_APPS = ['django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.auth', 'django.contrib.admin', 'alkimikis.users']
MIDDLEWARE_CLASSES = ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
Ideas for solution or deeper debugging? Anyone?
It's request.session. Lower case.
To debug, use the unit test framework. You can then add print statements and see the results.
print request
Very helpful.

TemplateSyntaxError while moving from django 1.1 to 1.2.1

I am moving my Django app from v1.1 to v1.2.1
However I am stuck on a TemplateSyntax error as seen below. I have not made any other changes to my app
TemplateSyntaxError at /
Caught ImportError while rendering: No module named urls
None of my url reverses in the template seem to work. Here is the culprit line:
{% trans 'Home' %}</div>
It looks like the Template context can't find the url resolver. Here is how my settings look like:
...
ROOT_URLCONF = 'myproject.urls'
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.humanize',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.sitemaps',
'myapp',
)
...
This one I just got myself after making some (fairly sweeping) changes. I suspect I made a mistake somewhere in a form, template, or view, and Django reports a misleading error...
(my pages worked pre-change in 1.2.1)