A 400 Bad Request in Django when starting out is often due to ALLOWED_HOSTS
being set to an empty list.
Set it as:
ALLOWED_HOSTS = ['*']
In its default configuration Django doesn’t log details of the problem in this
case. Would recommend adding to Django settings module:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
},
}
This will cause Django to log details of problems it captures to the console so
they appear in the Apache error log. If you add this first and try again you
hopefully will see a message about ALLOWED_HOSTS being the issue and can thus
confirm that as the problem.
Graham
> On 9 Jun 2016, at 2:34 PM, domca macdo <[email protected]> wrote:
>
>
> certainly remove the TEMPLATE_DEBUG parameter as you indicated and now no
> error in the log but the answer is in the browser (Bad Request ( 400 ) ) is
> generated ... I think it is an advance :) the problem now without error in
> the log not which way to go
>
> El jueves, 9 de junio de 2016, 0:05:13 (UTC-4), Graham Dumpleton escribió:
> Okay, I don’t know why it mentions TEMPLATE_DEBUG, but the code where the
> error arises is:
>
> class BaseEngine(object):
>
> # Core methods: engines have to provide their own implementation
> # (except for from_string which is optional).
>
> def __init__(self, params):
> """
> Initializes the template engine.
>
> Receives the configuration settings as a dict.
> """
> params = params.copy()
> self.name <http://self.name/> = params.pop('NAME')
> self.dirs = list(params.pop('DIRS'))
> self.app_dirs = bool(params.pop('APP_DIRS'))
> if params:
> raise ImproperlyConfigured(
> "Unknown parameters: {}".format(", ".join(params)))
>
> Clicking down through documentation one gets to:
>
>
> https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-TEMPLATES-OPTIONS
>
> <https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-TEMPLATES-OPTIONS>
>
> and then:
>
>
> https://docs.djangoproject.com/en/1.9/topics/templates/#django.template.backends.django.DjangoTemplates
>
> <https://docs.djangoproject.com/en/1.9/topics/templates/#django.template.backends.django.DjangoTemplates>
>
> what it suggests to me is that:
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
>
> isn’t set up right.
>
> Specifically, after is has thrown away keys in that dictionary it knows
> about, there are some left which it isn’t expecting and gives an error.
>
> What do you have TEMPLATES set to in the Django settings file?
>
> Graham
>
>> On 9 Jun 2016, at 1:57 PM, domca macdo <ing....@ <>gmail.com
>> <http://gmail.com/>> wrote:
>>
>> The article indicates that the version 1.8 is not a parameter that is used
>> as I mention it, but the state parameter is false since the creation of
>> startproject
>> my setting.py is : """Django settings for yarv1 project.
>>
>> Generated by 'django-admin startproject' using Django 1.9.5.
>>
>> For more information on this file, see
>> https://docs.djangoproject.com/en/1.9/topics/settings/
>> <https://docs.djangoproject.com/en/1.9/topics/settings/>
>>
>> For the full list of settings and their values, see
>> https://docs.djangoproject.com/en/1.9/ref/settings/
>> <https://docs.djangoproject.com/en/1.9/ref/settings/>
>> """
>>
>> import os
>> import os.path
>>
>> # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>>
>>
>> # Quick-start development settings - unsuitable for production
>> # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
>> <https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/>
>>
>> # SECURITY WARNING: keep the secret key used in production secret!
>> SECRET_KEY = 'sh0#%f)bi!)rx9(3h+@swser-bpsuh1w5sb%9fc742gs-0f4vb'
>>
>> # SECURITY WARNING: don't run with debug turned on in production!
>> DEBUG =False
>>
>> ALLOWED_HOSTS = []
>>
>>
>> # Application definition
>>
>> INSTALLED_APPS = [
>> 'django.contrib.admin',
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> 'cobrador',
>> 'mod_wsgi.server',
>> ]
>>
>> MIDDLEWARE_CLASSES = [
>> 'django.middleware.security.SecurityMiddleware',
>> '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',
>> ]
>>
>> ROOT_URLCONF = 'yarv1.urls'
>>
>> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': [],
>> 'APP_DIRS': True,
>> 'TEMPLATE_DEBUG':False,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> ],
>> },
>> },
>> ]
>>
>> WSGI_APPLICATION = 'yarv1.wsgi.application'
>>
>>
>> # Database
>> # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
>> <https://docs.djangoproject.com/en/1.9/ref/settings/#databases>
>>
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.sqlite3',
>> 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
>> }
>> }
>>
>>
>> # Password validation
>> #
>> https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
>> <https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators>
>>
>> AUTH_PASSWORD_VALIDATORS = [
>> {
>> 'NAME':
>> 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
>> },
>> {
>> 'NAME':
>> 'django.contrib.auth.password_validation.MinimumLengthValidator',
>> },
>> {
>> 'NAME':
>> 'django.contrib.auth.password_validation.CommonPasswordValidator',
>> },
>> {
>> 'NAME':
>> 'django.contrib.auth.password_validation.NumericPasswordValidator',
>> },
>> ]
>>
>>
>> # Internationalization
>> # https://docs.djangoproject.com/en/1.9/topics/i18n/
>> <https://docs.djangoproject.com/en/1.9/topics/i18n/>
>>
>> LANGUAGE_CODE = 'en-us'
>>
>> TIME_ZONE = 'UTC'
>>
>> USE_I18N = True
>>
>> USE_L10N = True
>>
>> USE_TZ = True
>>
>>
>> STATIC_URL = '/satic/'
>> STATIC_ROOT = "/var/www/domcanet.com/yarv1/static/
>> <http://domcanet.com/yarv1/static/>"
>> STATIC_DOC_ROOT = '/var/www/domcanet.com/yarv1/imagene'
>> <http://domcanet.com/yarv1/imagene'>
>> El miércoles, 8 de junio de 2016, 23:34:06 (UTC-4), Graham Dumpleton
>> escribió:
>> How are you using TEMPLATE_DEBUG setting in Django settings module. The
>> error would suggest something about that isn’t set correctly.
>>
>> https://docs.djangoproject.com/en/1.9/ref/settings/#template-debug
>> <https://docs.djangoproject.com/en/1.9/ref/settings/#template-debug>
>>
>> That documentation also suggests that the setting is deprecated since Django
>> 1.8. If using newer Django version, look at using the alternative suggested.
>>
>> Graham
>>
>>> On 9 Jun 2016, at 1:30 PM, domca macdo <ing....@ <>gmail.com
>>> <http://gmail.com/>> wrote:
>>>
>>> [Wed Jun 08 23:01:30.104809 2016] [mpm_event:notice] [pid 26572:tid
>>> 139843938969472] AH00489: Apache/2.4.10 (Debian) mod_wsgi/4.5.2
>>> Python/2.7.9 configured -- resuming normal operations
>>> [Wed Jun 08 23:01:30.104850 2016] [core:notice] [pid 26572:tid
>>> 139843938969472] AH00094: Command line: 'apache2 (mod_wsgi-express) -f
>>> /tmp/mod_wsgi-localhost:8000:1000/httpd.conf -D
>>> MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D
>>> MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D
>>> FOREGROUND'
>>> [Thu Jun 09 03:01:42.525404 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> mod_wsgi (pid=26574): Exception occurred processing WSGI script
>>> '/tmp/mod_wsgi-localhost:8000:1000/htdocs/home'.
>>> [Thu Jun 09 03:01:42.525459 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> Traceback (most recent call last):
>>> [Thu Jun 09 03:01:42.525478 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/mod_wsgi-4.5.2-py2.7-linux-x86_64.egg/mod_wsgi/server/__init__.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/mod_wsgi-4.5.2-py2.7-linux-x86_64.egg/mod_wsgi/server/__init__.py>",
>>> line 1381, in handle_request
>>> [Thu Jun 09 03:01:42.526117 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> return self.application(environ, start_response)
>>> [Thu Jun 09 03:01:42.526133 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py>",
>>> line 177, in __call__
>>> [Thu Jun 09 03:01:42.526223 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> response = self.get_response(request)
>>> [Thu Jun 09 03:01:42.526235 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py>",
>>> line 221, in get_response
>>> [Thu Jun 09 03:01:42.526349 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> response = self.get_exception_response(request, resolver, 400, exc)
>>> [Thu Jun 09 03:01:42.526362 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py>",
>>> line 102, in get_exception_response
>>> [Thu Jun 09 03:01:42.526381 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
>>> [Thu Jun 09 03:01:42.526389 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/core/handlers/base.py>",
>>> line 296, in handle_uncaught_exception
>>> [Thu Jun 09 03:01:42.526402 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> return callback(request, **param_dict)
>>> [Thu Jun 09 03:01:42.526410 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/utils/decorators.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/utils/decorators.py>",
>>> line 149, in _wrapped_view
>>> [Thu Jun 09 03:01:42.526483 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> response = view_func(request, *args, **kwargs)
>>> [Thu Jun 09 03:01:42.526494 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/views/defaults.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/views/defaults.py>",
>>> line 60, in server_error
>>> [Thu Jun 09 03:01:42.526548 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> template = loader.get_template(template_name)
>>> [Thu Jun 09 03:01:42.526558 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/loader.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/loader.py>",
>>> line 26, in get_template
>>> [Thu Jun 09 03:01:42.526633 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> engines = _engine_list(using)
>>> [Thu Jun 09 03:01:42.526644 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/loader.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/loader.py>",
>>> line 143, in _engine_list
>>> [Thu Jun 09 03:01:42.526669 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> return engines.all() if using is None else [engines[using]]
>>> [Thu Jun 09 03:01:42.526678 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/utils.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/utils.py>",
>>> line 110, in all
>>> [Thu Jun 09 03:01:42.526733 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> return [self[alias] for alias in self]
>>> [Thu Jun 09 03:01:42.526742 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/utils.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/utils.py>",
>>> line 101, in __getitem__
>>> [Thu Jun 09 03:01:42.526757 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> engine = engine_cls(params)
>>> [Thu Jun 09 03:01:42.526765 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/backends/django.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/backends/django.py>",
>>> line 32, in __init__
>>> [Thu Jun 09 03:01:42.526826 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> super(DjangoTemplates, self).__init__(params)
>>> [Thu Jun 09 03:01:42.526836 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>] File
>>> "/var/www/domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/backends/base.py
>>>
>>> <http://domcanet.com/yarv1env/local/lib/python2.7/site-packages/django/template/backends/base.py>",
>>> line 29, in __init__
>>> [Thu Jun 09 03:01:42.526889 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> "Unknown parameters: {}".format(", ".join(params)))
>>> [Thu Jun 09 03:01:42.526910 2016] [wsgi:error] [pid 26574:tid
>>> 139843804907264] [remote 127.0.0.1:20716 <http://127.0.0.1:20716/>]
>>> ImproperlyConfigured: Unknown parameters: TEMPLATE_DEBUG
>>>
>>>
>>>
>>>
>>> El miércoles, 8 de junio de 2016, 23:25:38 (UTC-4), Graham Dumpleton
>>> escribió:
>>>
>>>> On 9 Jun 2016, at 1:22 PM, domca macdo <[email protected] <>> wrote:
>>>>
>>>> Hello am with my first project with django and I tell you that I have 2
>>>> days trying to run it on apache .. I started doing it by installing and
>>>> configuring apache mod_wgsi in the same apache to run my django project
>>>> which unfortunately fails to do this morning in my I see this other method
>>>> work mod_wgsi express just get home started in an attempt to ride I think
>>>> ye come a long way since achieving install everything according to
>>>> parameters set in my virtual environment where I stayed in my project ....
>>>> but right now I an error that I can not solve ... run my server with the
>>>> following command (mod_wsgi start-server-express --application-type module
>>>> yarv1.wsgi) the server starts without any warning or apparent problem ...
>>>> but when I try to access (http://127.0.0.1:8000/home/
>>>> <http://127.0.0.1:8000/home/>) skips a 500 error page not found and when I
>>>> see in the log out the following (Exception occurred processing WSGI
>>>> script '/ tmp / mod_wsgi-localhost: 8000: 1000 / htdocs /home'. ) You
>>>> think I have something misconfigured could help in this case I remain
>>>> attentive greetings
>>>
>>> Normally after:
>>>
>>> Exception occurred processing WSGI script '/ tmp / mod_wsgi-localhost:
>>> 8000: 1000 / htdocs /home’.
>>>
>>> You should see a Python traceback and details of an exception. Do you see
>>> that? Can you provide the full message that is down from that point onwards?
>>>
>>> Thanks.
>>>
>>> Graham
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "modwsgi" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to modwsgi+u...@ <>googlegroups.com <http://googlegroups.com/>.
>>> To post to this group, send email to mod...@ <>googlegroups.com
>>> <http://googlegroups.com/>.
>>> Visit this group at https://groups.google.com/group/modwsgi
>>> <https://groups.google.com/group/modwsgi>.
>>> For more options, visit https://groups.google.com/d/optout
>>> <https://groups.google.com/d/optout>.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "modwsgi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <>.
>> To post to this group, send email to [email protected] <>.
>> Visit this group at https://groups.google.com/group/modwsgi
>> <https://groups.google.com/group/modwsgi>.
>> For more options, visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.