2017-01-17 26 views
-1

在我的項目中,我使用Django作爲後端,Angular 1作爲前端。 當我嘗試將圖片添加到我的HTML如下{% static 'image/location/img.png'%}我得到這個性質渲染圖像django和angular 1

http://localhost:3000/%7B%%20static%20'image/location/img.png'%%7D 404 (Not Found)

的404。任何人都可以幫助我設置 {%static ....%}工作。

在同樣的筆記<img ng-src="/static/image/location/img.png"/>工作正常,但這種方法似乎相當硬編碼,寧願使用第一種方法。

+0

不能使用JavaScript文件裏的模板語法......請嘗試創建一個[MCVE] – Sayse

+0

但爲什麼會這樣的代碼{%extends「base.html」%}在同一個文件中工作正常。我會盡力編輯我剛纔的問題 – Tatenda

回答

0

如果你有媒體文件服務設置與Apache和wsgi或任何其他你只需調用圖像的URL你已經放置它。

對於測試,您還可以在您的主要url文件中使用此static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

而在你的角度應用程序,你會說它是這樣的:<img ng-src="localhost:8000/media/image/location/img.png"/>