Possible Duplicate:
ImproperlyConfigured: Middleware module “django.middleware.csrf” does not define a “CsrfResponseMiddleware” class
I am getting the above message while running my django application. I put debug true but instead of getting standard django error I am getting
A server error occurred. Please contact the administrator.
# Django settings for mysite1 project.
import os.path
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('rohit', 'rohitdwivedi51@gmail.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/home/rohitd/workspace/slm_uidatabase.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.
# 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/"
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), "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 = '/media/'
# 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/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# 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 = '88^$#do)us^kzil0dtm7$t_0mrppz%p+mskovdq(ww0fi4i9o2'
# 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',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.csrf',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
#This got added to view the post, not suggestable but need to use this.
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'slm_ui.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/deepakt/mysite1/templates/"
"/home/rohitd/workspace/slm_ui/templates"
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'slm_ui.dashboard',
'slm_ui.networking',
'slm_ui.firewall',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# 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.
# 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,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
And my error log is here ………..
Traceback (most recent call last):
File "/usr/lib/python2.6/wsgiref/handlers.py", line 93, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 216, in __call__
self.load_middleware()
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 51, in load_middleware
raise exceptions.ImproperlyConfigured('Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname))
ImproperlyConfigured: Middleware module "django.middleware.csrf" does not define a "CsrfResponseMiddleware" class
Да, я читал местные топики про статичные файлы в Django … не помогло…
Итак делаю и запускаю все из под PyCharm … и имеет место быть вот такая конструкция:
from django.http import HttpResponse, Http404 import PIL # библиоткеа работы с графикой from PIL import Image, ImageDraw def indicator ( request ) : szHTML = "" image = Image.new("RGBA", (320,320), (0,0,0,0)) draw = ImageDraw.Draw(image) draw.ellipse( (10,10,300,300), fill="red", outline="blue") del draw image.save("/как-то-путь/django/invest_mice/static/test.png", "PNG") szHTML += "<br /><img src='/static/test.png' />" return HttpResponse ( szHTML )
Соответственно в STATIC.PY пишу:
STATIC_ROOT = '/как-то-путь/django/invest_mice/static/' STATIC_URL = '/static/' STATICFILES_DIRS = ( '/как-то-путь/django/invest_mice/static', )
Картинка в папочке появляется но вызывать ее не получается. Обращение по:
http://127.0.0.1:8000/static/img/test.png
Отдает текстовое сообщение:
A server error occurred. Please contact the administrator.
Никаких 404 и прочего… Напоминаю, что все это из под PyCharm…
В какой бубен стучать?
T
In the following microsoft documentation link, you can see how to fix your installation. https://support.microsoft.com/es-es/help/969052/how-to-restore-the-missing-windows-installer-cache-files-and-resolve-p Procedure 1: Use a command sequenceTo complete the steps of this procedure, you will need to copy the FindSQLInstalls.vbs command sequence from the «More information» section in a local folder on the computer where you are trying to update your SQL Server installation.Note: The FindSQLInstalls.vbs command sequence collects the information to correct the package access routes is not valid. And this command sequence is used with the source locations to ensure that all MSP packages are in the Windows Installer cache directory. If the original medium is available, the missing packages are added again.To solve these problems by using a command sequence, follow these steps:
Look for the directory where you saved the contents of the command sequence.
Open a system symbol with elevated privileges for the directory which saved the command sequence and execute the following command:
Cscript FindSQLInstalls.vbs %computername%_sql_install_details.txt
Open the file from step 2 in a text editor like the Notepad and identify the problems that are causing the error. To do this, look for the text file for the chain models as follows:
No.
!!!
Based on the results in step 3, follow the necessary steps.Note: Find out more about these steps in the «Examples» section.Repeat steps from 2 to 4 until the text file that was created in step 2 no longer contains text that refers to invalid routes or missing files for the component that is being updated.ExamplesThe following examples are inputs and explanations of the actions described in the output file generated when the FindSQLInstalls.vbs command sequence is executed.Example 1: Lack of installer filesThe following is an example of the output generated when a .msi package is missing in the Windows Installer cache folder.================================================================================
PRODUCT NAME : Microsoft SQL Server 2008 Database Engine Services
Product Code: {9FFAE13C-6160-4DD0-A67A-DAC5994F81BD}
Version : 10.2.4000.0
Most Current Install Date: 20110211
Target Install Location:
Registry Path:
HKEY_CLASSES_ROOTInstallerProductsC31EAFF906160DD46AA7AD5C99F418DBSourceList
Package : sql_engine_core_inst.msi
Install Source: x64setupsql_engine_core_inst_msi
LastUsedSource: m;1;G:x64setupsql_engine_core_inst_msi
The LastUsedSource line points to the location used to run the installation program.In the line «LastUsedSource», the entry m; means average and indicates that the origin of the CD or DVD media.In the following example, the origin is a CD or a DVD in the G drive. If the installation occurred from a file folder or from a shared network resource, the line starts with a North input; «LastUsedSource» followed by a Numeric_Data_Name entry; and the actual access route:!!!! sql_engine_core_inst.msi DOES NOT exist on the path in the path G:x64setupsql_engine_core_inst_msi !!!!
Action needed, re-establish the path to G:x64setupsql_engine_core_inst_msi
The «necessary action» line shows the complete access path that must exist in order to update the missing files for the original installation medium:Installer Cache File: C:WINDOWSInstaller19b4d2.msi
The «Archivo de cache delinstaller» line Confirms the name of the installer cache file:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! C:WINDOWSInstaller19b4d2.msi DOES NOT exist in the Installer cache. !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The following section of the output reports the actions required to resolve missing files: Action needed, recreate or re-establish path to the directory:
G:x64setupsql_engine_core_inst_msithen rerun this script to update installer cache and results
The path on the line above must exist at the root location to resolve
this problem with your msi/msp file not being found or corrupted,
In some cases you may need to manually copy the missing file or manually
replace the problem file overwriting it is exist:
Copy «G:x64setupsql_engine_core_inst_msisql_engine_core_inst.msi» C:WINDOWSInstaller19b4d2.msi
Replace the existing file if prompted to do so.
Example 2: Revisions missingRevisions that are missing can produce entries similar to those of example 1. Most of the cases, you will notice that tickets on the LastUsedSource Patch line that refer to a review and this line is similar to the following:Patch LastUsedSource: n;1;c:ca91e857a4f12dd390f0821a3HotFixSQLFiles
This result indicates the following about the installation of the review:The original revision was installed by double-clicking the executable file of the review.
The revision installer uses a temporary folder, c:ca91e857a4f12dd390f0821a3, during the installation of the review.
To re-create the access path, you must run the same executable and add the following parameter:
/x:c:ca91e857a4f12dd390f0821a3
Note: This command makes the executable file to extract the files to the previous missing location and creates the structure that is required to update the Windows installer cache with the missing files. The actual location will vary and have a unique review as a service pack that is extracted in several locations. Each product installed, includes a section containing the following information for «Parches installed»:
Display name:
KB Article URL: http://support.microsoft.com/?kbid= Patch LastUsedSource: The «KB Article URL» line can help download any means of the review, if necessary.Procedure 2: Manually restore filesTo manually restore missing files from Windows Installer cache, follow these steps:
Collect all the details about the file missing from the error message, from the installation log file or the registry entries that are maintained by the Windows installer. For example, in the Error 1 message in the «Symptoms» section, all the information necessary to solve the problem is present in the error message:
PatchName: «Review 1702 for SQL Server 2008 R2 (KB981355) (64 bits)»
Original MSP file used by security review: sql_engine_core_inst.msp
MSP cache file: c:WindowsInstaller1fdb1aec.msp
If you do not have all the details, refer to the «More information for Procedure 2» section to see the steps to collect these details.Visit http://support.microsoft.comy Look for the KB article that is associated with this review. In this example, you should look for KB981355.
Download this review package on your computer. Be sure to download the review package that corresponds to the required platform. In this example, the package is SQLServer2008R2-KB981355-x64.exe.
Remove the contents of the revision package using the following syntax:C:Temp>SQLServer2008R2-KB981355-x64.exe /x C:TempSQLServer2008R2-KB981355-x64
Search for the original msp file sql_engine_core_inst.msp The file should be in the following folder:C:TempSQLServer2008R2-KB981355-x64x64setupsql_engine_core_inst_msi
Copy this original msp file to the following Windows Installer cache:%windir%installer
Cambie el nombre del archivo msp original, sql_engine_core_inst.msp, a la siguiente:
1fdb1aec.msp de archivo msp en caché
You can start the update program that occurred the error and resume the update process. You can find this message for a Windows Installer cache file that is missing for another component or another update of the same product.To get a list of all missing files Windows Installer cache that are related to SQL Server product components, you can download the SQL Server 2008 R2 BPA tool mentioned in the «More information» section.If the error message refers to a missing Windows Installer (.msi) database file, it is not necessary to perform steps 2 to 4. Instead, you can go directly to step 5. You have to locate the .msi file from the original medium you used to install the product. If this error message was generated for sql_engine_core_inst.msi, you have to search this file from the installation medium in the following folder structure:x64setupsql_engine_core_inst_msi
The other steps are the same.For more information on procedure 2How to get the revision package and the product details missing a .msp fileDifferent versions of the product, generate different error messages for this problem. Error messages mentioned in the «Symptoms» section appear for updates installation programs from Microsoft SQL Server 2008 SP1. For other updates, you will receive error messages that cannot be clearly specified which revision file does not exist in the Windows Installer cache and the specific update details. These error messages, the configuration log files will contain information about the missing Windows Installer cache file. Example of installation record similar to the following:MSI (s) (FC:F8) [13:48:58:649]: Opening existing patch ‘C:WINDOWSInstaller145258.msp’.
MSI (s) (FC:F8) [13:48:58:649]: Couldn’t find local patch ‘C:WINDOWSInstaller145258.msp’. Looking for it at its source.
MSI (s) (FC:F8) [13:48:58:649]: Resolving Patch source.
MSI (s) (FC:F8) [13:48:58:649]: Note: 1: 2203 2: D:cda162709d239766830bae5ce12bHotFixSQLFilessqlrun_sql.msp 3: -2147287037
MSI (s) (FC:F8) [13:48:58:649]: SOURCEMGMT: Source is invalid due to missing/inaccessible package.
MSI (s) (FC:F8) [13:49:29:961]: Product: Microsoft SQL Server 2005 — Installation failed.
MSI (s) (FC:F8) [13:49:29:992]: MainEngineThread is returning 1635
This patch package could not be opened. Verify that the patch package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer patch package.
D:SQL2K5ServersSetupSqlRun_SQL.msi
If you carefully examine the installation record, you already provide the information on the original MSP file that was used the following review:sqlrun_sql.msp
For more details about the missing .msp file in the Windows Installer cache, follow these steps:Busque el archivo .msp que falta en la siguiente subclave del registro de revisiones de Windows Installer:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Patches
Encontrar el GUID de la revisión.
Buscar el GUID de la revisión en la siguiente subclave del registro de productos de Windows Installer:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products
Para el registro de instalación de ejemplo, la información sobre el archivo .msp que falta y los detalles de revisión correspondientes están presentes en las entradas del registro siguientes:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18PatchesA3B085EA74A9A7640A496636F7EF9A44
Valor: 0
Nombre: LocalPackage
Datos: C:WINDOWSInstaller145258.msp
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionInstallerUserDataS-1-5-18Products1EB3A031CC585314E87AA527E46EECC2PatchesA3B085EA74A9A7640A496636F7EF9A44 Valor: 6
Nombre: DisplayName
Datos: GDR 2050 para SQL Server la base de datos Services 2005 ENU (KB932555)
Now you have all the information points to start the steps to resolve missing files in the Windows Installer cache.Note: If you use Microsoft SQL Server 2008 Service Pack 3 (SP3) or a later version, you can also receive a similar error message for missing .msi files. By using this error message, you can quickly determine which missing file, which service pack to download, and where you can find the download.