I have followed the tutorial to make a new Django-CMS (2.4) site. I am only using a single language (English).
There is an automatic redirect to include the language identifier '/en/' in my site's URLs. How do I remove it?
thanks.
Option 1:
Set USE_I18N = False in your settings file.
Django’s internationalization hooks are on by default... If you don’t use internationalization, you should take the two seconds to set USE_I18N = False in your settings file. [Django documentation:Translation]
The internationalization is "inherited" from Django. Django-cms 2.4 uses Django 1.5 which supports internationalization and the use of USE_I18N flag. The flag has been used in all successive django releases.
Option 2:
replace this pattern registration:
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
with this:
from django.conf.urls import patterns
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
The tutorial you pointed to uses the i18n_patterns method which does exactly this: prepends the language code to your urls.
Also note you can safely remove 'django.middleware.locale.LocaleMiddleware' and 'cms.middleware.language.LanguageCookieMiddleware' from your MIDDLEWARE_CLASSES if you will not use multiple languages.
#ppetrid's answer is still correct. However, as of Django 1.6 patterns is no longer available. Change the existing code to this:
from django.conf.urls import patterns
urlpatterns = (
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
You will also get a warning if you leave the '', in the patterns too.
In django version 1.8.18 you just need to put False at this variable in settings.py
USE_I18N = False
USE_L10N = False
If you want to keep one language in the URL, for instance because you have backlinks in the web with the language code, you can simply take out the other language in settings.py
LANGUAGES = (
#('en', gettext('en')),
('de', gettext('de')),
)
CMS_LANGUAGES = {
'default': {
'public': True,
'hide_untranslated': False,
'redirect_on_fallback': True,
},
1: [
{
'public': True,
'code': 'de',
'hide_untranslated': False,
'name': gettext('de'),
'redirect_on_fallback': True,
},
# {
# 'public': True,
# 'code': 'en',
# 'hide_untranslated': False,
# 'name': gettext('en'),
# 'fallbacks': ['de'],
# 'redirect_on_fallback': True,
# },
],
}
That way the URL still shows www.example.com/de/foo.html. In the Example above, that /de/ will be lost, which will render all your URLs in the web meaningless.
Thus, from an SEO perspective, it might not be the best option if you have already built up links with the language code in it.
Related
It seems I don't understand how to set the default language for Django CMS. I want the default language to be set to Dutch. However, for an unknown reason, it always defaults to English when creating or after modifying/editing a Page.
Take the following scenario. I open the Page tree. English is selected by default. I select Dutch. I edit this page. I publish it. I click on edit, it opens the English page which is empty.
Take another scenario. I open the Page tree. I create a new page. By default it opens for the English variant.
Note: All cookies were removed as suggested in the documentation.
Please advise how I can set the default language to Dutch?
The settings:
from django.utils.translation import gettext_lazy as _
LANGUAGE_CODE = "nl"
SITE_ID = 1
USE_I18N = True
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.common.BrokenLinkEmailsMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
]
LANGUAGES = [
('nl', 'Dutch'),
('en', 'English'),
]
CMS_LANGUAGES = {
1: [
{
'code': 'nl',
'name': _('Dutch'),
'fallbacks': ['en', ],
'public': True,
'hide_untranslated': True,
'redirect_on_fallback': False,
},
{
'code': 'en',
'name': _('English'),
'public': True,
},
],
'default': {
'fallbacks': ['nl', 'en'],
'redirect_on_fallback': False,
'public': True,
'hide_untranslated': True,
}
}
I fixed the problem as follows per the documentation:
# urls.py
from django.conf.urls.i18n import i18n_patterns
from django.views.i18n import JavaScriptCatalog
# ...
admin.autodiscover()
urlpatterns = i18n_patterns(
re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
)
# Note the django CMS URLs included via i18n_patterns
urlpatterns += i18n_patterns(
path(settings.ADMIN_URL, admin.site.urls),
re_path(r'^', include('cms.urls')),
)
urlpatterns += [
...
]
This setup introduces other minor issues that need to be fixed. But in general, this is the solution.
On another note, not sure though as to why this part is needed:
re_path(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog')
I'm having a problem with Django loading the correct translation (.po/.mo) files.
I know my translations are working because when I change the LANGUAGE_CODE to 'fr' I can see my string translated.
LANGUAGE_CODE = 'nl'
LANGUAGES = (
('nl', 'Nederlands'),
('fr', 'Frans'),
)
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
]
TIME_ZONE = 'UTC'
USE_I18N = True
But when I set my translations to use the i18n_patterns in urls.py it is not loading my French (fr) translations when I visit: 127.0.0.1:8000/fr/about/ it still loads the Dutch (nl) values.
Funny thing is when I visit 127.0.0.1:8000/fr/admin/ I can see it loads the French admin values and when I visit 127.0.0.1:8000/nl/admin/ it loads the Dutch ones... I must be doing something wrong.
urls.py
urlpatterns = i18n_patterns(
url(r'^$', 'homepage.views.index', name="homepage"),
url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^contact/', 'homepage.views.contact_us', name="contact"),
url(r'^about/', 'homepage.views.about', name="about"),
url(r'^admin/', include(admin.site.urls)),
url(r'^jobs/', include(job_urls)),
url(r'^news/', include(news_urls)),
url(r'^search/', include('haystack.urls')),
url(r'^content/(?P<slug>[^\.]+)', 'homepage.views.content', name="view_content"),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
You need to import ugettext_lazy as _ in your models.py and forms.py, instead of the regular ugettext. ugettext will evaluate the translations during import, at which point it has no other choice than to use the default language; ugettext_lazy will evaluate when rendering, at which point it has the correct language information available.
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 the pages throw a 404 error on a site for users who are not logged in. But if I log in to the admin and go back to view the site, all the pages are fine and viewable.
I've been using Django CMS for years and haven't come across this before. The only difference with this site is the default language is french, in my settings I have:
LANGUAGES = [
('fr', 'Francais'),
]
as my LANGUAGES setting and here is my LANGUAGE_CODE
LANGUAGE_CODE = 'fr'
Here are my urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
and my middleware...
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.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
)
What could be the cause of this?
I was in a similar situation to you: I'm using multiple languages with Django-CMS.
My issue was related to the CMS_LANGUAGES variable I'd defined: I'd simply lifted a portion of the example from the docs.
A comment on a GitHub issue helped point me in the correct direction.
I'd previously had the variable set up as:
CMS_LANGUAGES = {
...
'default': {
'fallbacks': ['en', 'de', 'fr'],
'redirect_on_fallback': False,
'public': False,
'hide_untranslated': False,
}
}
Notice the definition of the public boolean.
Also, make sure that you follow the instructions in the documentation with respect to setting up your language variables within the CMS_LANGUAGES dictionary.
Replacing the above with 'public': True got things working for me again.
Just add a plus sign :)
if settings.DEBUG:
urlpatterns += patterns('',
I have read many answers here but none did answer my exact question.
I did the part one, the polls. I started part 2, the admin, however, after runserve, when i try to acces the page, here is the error i get (my project name is john):
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in john.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. ``
My code - urls.py:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'newgrid.views.home', name='home'),
# url(r'^newgrid/', include('newgrid.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Models.py:
from django.db import models
import datetime
from django.utils import timezone
# Create your models here.
from django.db import models
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
settings.py:
# Django settings for newgrid project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'C:/john/john/johny.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # 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.
# In a Windows environment this must be set to 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
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# 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 = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# 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',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'cl8%_lzxbct-^ebmpje25%r&5*0=$qmv9gw6i$^arox*kr4$_e'
# 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',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'newgrid.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'newgrid.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.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
#'django.contrib.admindocs',
'polls'
)
# 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.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
Thats about it. Oh yea, im in WinXP.
You're navigating to the wrong URL. As the tutorial says,
Now, open a Web browser and go to /admin/ on your local domain — e.g., http://127.0.0.1:8000/admin/. You should see the admin's login screen:
In your URLconf, you haven't defined a view for the root URL, that's why your application will only work if you point your browser to a URL starting with admin/
Uncomment the following line:
# url(r'^$', 'newgrid.views.home', name='home'),
and change 'newgrid.views.home' to an existing view, maybe something that renders a plain template containing some temporary links to play with.
I know this was asked a long time ago but perhaps people are still looking here for an answer to the same issue, as I was. For me, the problem that I made was which urls.py I had changed. the key is the change the PROJECT urls.py, not the APP urls.py file.
for example, if your PROJECT is called "mysite" and the APP is "polls" the file you want to change is located here:
/mysite/urls.py
NOT the app version (located in /polls/urls.py).
also, you may have mad the error I did which was to change /polls/urls.py to the new "namespace" syntax and then, after making that change to the /mysite/urls.py, forgetting to change /polls/urls.py back to the original code given in the "Writing more views" section of tutorial 3 (https://docs.djangoproject.com/en/1.7/intro/tutorial03/)
hope this helps someone. (it would be my first time contributig to StackOverflow!)
I worked through this tutorial also, and had a problem during part 3 which returned the same error; my confusion was with the directory structure.
I had written the urls.py file in the directory I thought the tutorial specified, but it was ~/mysite/urls.py whilst the tutorial had actually specified ~/mysite/mysite/urls.py
The file ~mysite/polls/urls.py, which the tutorial also prompts us to create, was located correctly, and I should've been suspicious that both sets of instructions only listed the inner directory (polls or mysite). I had to re-read part 1 of the tutorial after having this problem, but then I finally understood the following text from it:
The inner mysite/ directory is the actual Python package for your project.
You should try this Statement "url(r'^polls/', include('polls.urls'))," under urlpatterns class in "mysite/mysite/urls.py" file,then u can see what u desire
I has the same problem and now got the solution in two ways , by editing the urls.py in [mysite/mysite/urls.py] OR change the ROOT_URLCONF in the settings to urls.py if you already edit the urls.py in the path where manage.py exists.