既然这是Google的最佳结果,我想我应该添加另一种方法来做到这一点。我个人更喜欢这一点,因为它将实现留给了Django框架。
# Original answer said:# from django.templatetags.static import static# Improved answer (thanks @Kenial, see below)from django.contrib.staticfiles.templatetags.staticfiles import staticurl = static('x.jpg')# url now contains '/static/x.jpg', assuming a static path of '/static/'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)