我参与了一个使用whitenoise来提供静态文件的应用程序。它被配置为使用CompressedManifestStaticFilesStorage
,ManifestStaticFilesStorage
又使用ManifestStaticFilesStorage
。
静态文件,我指的是我们提供的静态文件,以及来自第三方的leaflet等库。
Django提供的_detectIconPath: function () {
var el = DomUtil.create('div', 'leaflet-default-icon-path', document.body);
var path = DomUtil.getStyle(el, 'background-image') ||
DomUtil.getStyle(el, 'backgroundImage'); // IE8
document.body.removeChild(el);
return path.indexOf('url') === 0 ?
path.replace(/^url\([\"\']?/, '').replace(/marker-icon\.png[\"\']?\)$/, '') : '';
}
类将重命名文件名以包含哈希。对于cachebusting。它过滤资源并更改对文件的未散列引用以包含散列。
这反过来打破了传单中的一个功能:
path
问题是url("https://example.org/static/path/leaflet/dist/images/marker-icon.2273e3d8ad92.png")
的价值如下:
https://example.org/static/path/leaflet/dist/images/marker-icon.2273e3d8ad92.png")
由于文件名不匹配,第二个替换将不会执行任何操作。这反过来将返回:
https://example.org/static/path/leaflet/dist/images/marker-icon.2273e3d8ad92.png")marker-icon.png
当传单尝试将文件名附加到此"目录"时,我们得到:
ManifestStaticFilesStorage
这显然是错误的。
那么解决方案是什么?我被告知,我们不应该尝试散列第三方软件包的文件名,否则可能会有其他破坏。但是,我没有看到CompressedManifestStaticFilesStorage
排除某些目录被散列的任何选项。
我创建了以下类来尝试解决此问题。我在设置中引用此类而不是class MyStorage(CompressedManifestStaticFilesStorage):
""" This class overrides the built in class and turns off file name hashing for selected directories. """
def _nonhashed_name_func(self, name, hashed_files=None):
name = posixpath.normpath(name)
cleaned_name = self.clean_name(name)
return cleaned_name
def _url(self, hashed_name_func, name, force=False, hashed_files=None):
split = name.split("/")
if split[0] in ['bower_components', 'node_modules']:
hashed_name_func = self._nonhashed_name_func
return super()._url(hashed_name_func=hashed_name_func, name=name, force=force, hashed_files=hashed_files)
。
- (void)viewDidLoad {
[super viewDidLoad];
self.displayDataTableView.delegate = self;
self.displayDataTableView.dataSource = self;
self.dateArray = [[NSMutableArray alloc]init];
self.amountArray = [[NSMutableArray alloc]init];
self.urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
self.urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"My host name"]];
self.dataTask = [self.urlSession dataTaskWithRequest:self.urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSMutableDictionary *serverRes = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
// NSLog(@"...%@ ", serverRes);
self.integer = [[serverRes objectForKey:@"Data"] count];
NSLog(@"************* = %lu", self.integer);
for (int i=0; i<self.integer; i++) {
[self.dateArray addObject:[[[serverRes objectForKey:@"Data"] objectAtIndex:i] objectForKey:@"Date"]];
[self.amountArray addObject:[[[serverRes objectForKey:@"Data"] objectAtIndex:i] objectForKey:@"TotalAmount"]];
}
NSLog(@"Date Array : %@", self.dateArray);
}];
[self.dataTask resume];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.integer;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailsCell" forIndexPath:indexPath];
return cell;
}else{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailsTitle" forIndexPath:indexPath];
return cell;
}
}
然而,这似乎是一个有点不优雅的解决方案。这里有人有更好的建议吗?
答案 0 :(得分:0)
我在Angular2的上下文中找到了描述类似问题的页面:
https://www.npmjs.com/package/@asymmetrik/angular2-leaflet#a-note-about-markers
在传单的特定情况下,解决方案似乎是覆盖默认图标路径。当我使用vue2-leaflet时,可以使用以下方法完成:
<v-icondefault :image-path="path"></v-icondefault>
根据源代码提供的example。