Django的失败,有时候,很反常行为 [英] django fails, sometimes, very erratic behavior

查看:179
本文介绍了Django的失败,有时候,很反常行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Django的响应不同,以相同的请求无缘无故可怕的问题。

I have terrible problems with django responding differently to the same requests for no apparent reason.

有时候,我刷新,我看到一个错误,那么我刷新和它走了,有时模板有关缺失值抱怨然后再以其精致,又没有任何解释。

Sometimes i refresh and I see an error, then I refresh and its gone, sometimes the template complains about a missing value then its fine again, again without explanation.

有时,它从生产服务器的图形,有时从开发服务器。

Sometimes it pulls the graphics from the production server, sometimes from the development server.

最糟糕的是,有时候,很多时候,一切看起来和加载罚款,但查询返回0命中甚至强硬基于相同的查询加载罚款,请问该怎么做查询管理失败的部分第二查询集的相同的请求里面呢?对于这最后一个我的理论,这是不是在所有获得从视图的查询集变量。

Worst of all, sometimes, very often, everything looks and loads fine, but a query returns 0 hits even tough a second queryset based on the same query loads fine, how does the same query manages to fail partially inside the same request? For this last one I have the theory that it isn't getting the queryset variable from the view at all.

我在为使用Google有关此问题的关键字的损失,我在移植项目到PHP因为至少它总是呈现相同的边缘。

I am at a loss of keywords for googling about this problem, I'm in the edge of porting the project to php because at least it always renders the same.

该项目使用的Apache2安装为WSGI,是每次我更新我一定要触摸wsgi.py 的WSGI脚本。

The project is installed as a wsgi using apache2, yes everytime i update I make sure to touch wsgi.py, the WSGI script.

请帮忙

Apache的虚拟主机配置:

apache's vhost config:

<VirtualHost *>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com

    DocumentRoot /home/self/example.com
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/self/example.com>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    Alias /media/ /home/self/projects/django/myapp/media/
    <Directory /home/self/projects/django/myapp/media/>
        Order deny,allow
        Allow from all
    </Directory>
    WSGIScriptAlias / /home/self/projects/django/myapp/wsgi.py
    <Directory /home/self/projects/django/myapp/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /home/self/example.com/error.log
    LogLevel warn
    CustomLog /home/self/example.com/access.log combined
    ServerSignature Off
</VirtualHost>

这是wsgi.py

import os
import sys
sys.path.append('/home/self/projects/django')
sys.path.append('/home/self/projects/django/myapp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

和settings.py

And settings.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

# Django settings for myapp project.
import os
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('My self', 'self@example.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'                           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = os.path.join(PROJECT_DIR, 'myapp.db') # 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 = ''             # 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.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Tegucigalpa'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
# LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'es-es'

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

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# 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 = ''

# 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 = 'http://media.example.com/media/'

AUTH_PROFILE_MODULE = "myapp.userprofile"
LOGIN_URL = "/login"

# Make this unique, and don't share it with anybody.
SECRET_KEY = '1(!u3tvq^=x)y@kny&^eg&uevo6&y%k-wgl$q$-sl_0+s%3g^5'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
#     'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'pagination.middleware.PaginationMiddleware',
)

ROOT_URLCONF = 'myapp.urls'

TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates'),
    # 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.
)

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
)

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'myapp',
    'pagination',
)

更新:

现在我敢肯定,模板做工精细,并正确地更新它的行为不正常,但withing的模式,他们表现出老行为的意见,有时

Now I'm positive, the templates work fine and are updated correctly it's the views that behave erratically but withing a pattern, they exhibit old behaviors, sometimes.

这听起来像一个缓存的问题,但我不这样做我自己的缓存,还有我总是做触摸wsgi.py 更新WSGI脚本是一切我应该需要刷新应用程序。

This sounds like a caching problem, but I'm not doing any caching on my own, also I always do touch wsgi.py to update the WSGI script which is everything I should need to refresh the application.

推荐答案

您存储全局变量的状态?如果这样,响应将取决于previous请求相同的过程不同。

Are you storing state in global variables? If so, the response will differ depending on previous requests to the same process.

放心,Django的是每天都有成千上万的网站可靠地使用。你的问题是不是特有的Django的。

Rest assured, Django is used reliably by thousands of sites every day. Your problem is not endemic to Django.

这篇关于Django的失败,有时候,很反常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆