我正在使用django-pipeline
加载静态文件。
奇怪的是,它StaticLiveServerTestCase
无法live_server_url
正确加载静态文件。
以下是部分代码:
class ProductSetupTestCase(TestCase):
@classmethod
def setUpClass(cls):
super(ProductSetupTestCase, cls).setUpClass()
# place category
cls.place_category = PlaceCategory.objects.create(name="학교")
# subject category
cls.subject_category1 = SubjectCategory.objects.create(name="사람")
cls.subject_category2 = SubjectCategory.objects.create(name="꽃병")
for i in range(5):
name = 'name' + str(i)
product = Product.objects.create(
name=name,
place_category=cls.place_category,
)
product.subject_category_set.add(cls.subject_category1)
product.subject_category_set.add(cls.subject_category2)
product.variation_set.create(color='black')
product.variation_set.create(color='single')
product.variation_set.create(color='multi')
class CartItemEditTest(ProductSetupTestCase, StaticLiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(2)
Firefox
浏览器出现,我执行以下命令:
self.browser.get(self.live_server_url) # self.live_server_url value is localhost:8081
当我js
使用开发工具检查文件时,它显示如下:
<script type="text/javascript" src="/static/js/message.8d038600d898.js" charset="utf-8"></script>
当我复制src
( http://localhost:8081/static/js/message.8d038600d898.js
) 并将其粘贴到新选项卡中时,它不显示Not Found
.
现在我使用了其他 url,http:localhost:8000
即django runserver url
.
self.browser.get(
http://localhost:8000 `)
当我这次检查时,它很好地加载了静态文件:
<script type="text/javascript" src="/static/js/message.js" charset="utf-8"></script>
为什么会这样?我应该不再使用live_server_url
吗?