Django多站点多个favicon.ico请求一个站点

时间:2014-01-14 01:43:17

标签: django

更新:明确指出它正在开发服务器上运行,因此答案/评论不会偏离提供静态文件的最佳做法,对我来说这与问题无关,因为根本没有图标。

我有一个django多站点设置运行相同的代码库 ON DEVELOPMENT SERVER ,站点A和站点B,由于某种原因,浏览到站点A导致多个请求到favicon.ico但没有发生在网站B。

登录网站A浏览到/

125.236.233.243 - - [14/Jan/2014:14:41:13 +1300] "GET / HTTP/1.1" 200 212 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
125.236.233.243 - - [14/Jan/2014:14:41:13 +1300] "GET /favicon.ico HTTP/1.1" 200 212 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
125.236.233.243 - - [14/Jan/2014:14:41:13 +1300] "GET /favicon.ico HTTP/1.1" 200 212 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
125.236.233.243 - - [14/Jan/2014:14:41:13 +1300] "GET /favicon.ico HTTP/1.1" 200 212 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
125.236.233.243 - - [14/Jan/2014:14:41:14 +1300] "GET /favicon.ico HTTP/1.1" 200 212 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"

记录站点B浏览到/

125.236.233.243 - - [14/Jan/2014:14:41:08 +1300] "GET / HTTP/1.1" 200 193 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"

我比较了设置,没有明显的理由说明会发生这种情况......

以下是网站A的设置

MEDIA_ROOT = join(VIRTUALENV_ROOT, 'public-www', 'media')

MEDIA_URL = '/media/'

STATIC_ROOT = join(VIRTUALENV_ROOT, 'public-www', 'static', 'sitea')

STATIC_URL = '/static/sitea/'

STATICFILES_DIRS = ( 
    join(PROJECT_ROOT,'static', 'sitea'),
    join(PROJECT_ROOT,'static'),
)

STATICFILES_FINDERS = ( 
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

TEMPLATE_LOADERS = ( 
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

这是网站B的设置,它使用网站A中的设置并覆盖一些设置:

import os
from os.path import join, dirname

PROJECT_ROOT = dirname(dirname(__file__))
VIRTUALENV_ROOT = dirname(PROJECT_ROOT)

try:
    from settings import *
except: pass

SITE_ID = 2
SITE_NAME = 'siteb'

TEMPLATE_DIRS = (
    join(PROJECT_ROOT, 'templates', SITE_NAME),
    join(PROJECT_ROOT, 'templates', 'sitea'),
    join(PROJECT_ROOT, 'templates'),
)

STATIC_ROOT = join(VIRTUALENV_ROOT, 'public-www', 'static', SITE_NAME)

STATIC_URL = '/static/{}/'.format(SITE_NAME)

STATICFILES_DIRS = (
    join(PROJECT_ROOT,'static', SITE_NAME),
    join(PROJECT_ROOT,'static'),
) 

更有趣的是,网站C与网站B具有相同(几乎不同的网站名称除外)设置,具有多个favicon.ico请求。 WEIRD。

0 个答案:

没有答案