請幫忙解決問題。如何更改模板?
我做了一個上傳照片的表單。
機型:
class UserProfile(User):
drum_photo = models.ImageField(
'Фото инструмента',
upload_to='userprofile/drum_photo/',
blank=True,
null=True,
)
形式:
class DrumDataForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = (
'drum_photo',
)
template.html:
<div class="cell image_outer">
<label class="label">{{ form.drum_photo.label }}</label>
{{ form.drum_photo }}
{% if drum_photo %}
{% thumbnail drum_photo "230x230" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}
{% endif %}
{{ form.drum_photo.errors }}
</div>
所得瀏覽器顯示以下標記:
<div class="cell image_outer">
<label class="label">foto</label>
now: <a href="/media/userprofile/drum_photo/kYNP5kPnTOU_2.jpg">userprofile/drum_photo/kYNP5kPnTOU_2.jpg</a> <input id="drum_photo-clear_id" name="drum_photo-clear" type="checkbox"> <label for="drum_photo-clear_id">Clear</label><br>Изменить: <input id="id_drum_photo" name="drum_photo" type="file">
<img src="/media/cache/0a/ca/0acac93baa399abad7d3c048ff20d5db.jpg" width="230" height="230">
</div>
問題是我需要更改佈局(添加或刪除一些元素)。請告訴我你在哪裏存儲需要更改的模板?
檢查settings.py,應該有一個名爲'TEMPLATE_DIRS'的設置,你會發現Django在哪裏存儲你的模板。然後,您應該檢查用於呈現模板的實際視圖的'views.py',更改模板會在渲染時更改它。 –
否。模板的一部分,負責顯示錶單下載文件不在TEMPLATE_DIRS中。它在覈心django中 – user3607370