那麼,我設計了一些東西,但我不知道,如何實現 它。包含塊沒有顯示在Django模板
models.py
class Notificaciones(models.Model):
IDcliente = models.ManyToManyField(User)
Tipo_de_notificaciones = ((1,'Ofertas'),(2,'Error'),(3,'Informacion'))
Tipo = models.IntegerField('Tipo de notificacion',choices=Tipo_de_notificaciones, default=3,)
Nombre_not = models.CharField("Nombre de la notifiacion",max_length=50)
Descripcion_not = HTMLField("Descripcion de la notificacion")
Imagen_not = models.ImageField("Imagen de la notificacion",upload_to="notificaciones")
Fecha_Caducidad_notificacion = models.DateTimeField("Fecha de caducidad de la notificacion",auto_now_add=False)
class Meta:
verbose_name = 'Notificacion'
verbose_name_plural = 'Notificaciones'
def __str__(self):
return self.Nombre_not
views.py
def notifi(request):
notifi = Notificaciones.objects.all()
return render_to_response('app/notificaciones.html',{ 'notifi' : notifi })
現在我要顯示在頁眉通知在燈箱廣告,然後在我的layout.html,其中標題,頁腳等被調用。但是當我打電話通知時,它不會出現。
<div id="notifiaciones" class="notificaciones notificacionesTrans" tabindex="-1" role="dialog" aria-hidden="true" >
{% include 'app/notificaciones.html' %}
</div>
有人可以解釋,如果我可以打電話從意見通知還是應該以某種方式做別的?
URL.PY
url(r'^tinymce/', include('tinymce.urls')),
url('', include('django.contrib.auth.urls', namespace='auth')),
url(r'^social/',include('social.apps.django_app.urls', namespace='social')),
#url(r'^s$', 'app.views.CategoriaProductoss', name='servicios'),
#url(r'^s/(?P<id>\d+)$', 'app.views.servicioscategoria', name='servicioscategoria'),
url(r'^notificaciones/$', 'app.views.notifi', name='notificaciones'),
url(r'^media/(?P<path>.*)$','django.views.static.serve', {'document_root':settings.MEDIA_ROOT,}),
url(r'^$', 'django.contrib.auth.views.login',{'template_name':'app/index.html'}, name='Vulpini.co'),
url(r'^$', 'django.contrib.auth.views.logout', name='logout'),
url(r'start$', 'app.views.start', name="start"),
url(r'ajax-upload$', 'app.views.import_uploader', name="my_ajax_upload"),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
Notificación.html
<ul>
{% for notifi in notifi %}
<li>{{ notifi.Tipo }}
{{ notifi.Nombre_not }}
<img src="{{ notifi.Imagen_not }}" alt="{{ notifi.Nombre_not }}"/>
{{ notifi.Fecha_Caducidad_notificacion }}
</li>
{% endfor %}
</ul>
登錄表單內的layout.html
<form action="/login" class="form-horizontal" method="post">
{% csrf_token %}
<h4>Iniciar Sesion.</h4>
<hr />
<div class="login-social">
<a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}" target="iframe">Iniciar sesion con Facebook</a>
<a href="{% url 'social:begin' 'twitter' %}?next={{ request.path }}" target="iframe">Iniciar sesion con Twitter</a>
</div>
<hr />
<div class="form-group">
<label class="control-label" for="inputEmail">Usuario</label>
<div class="controls">
<input name="username" type="text" id="inputEmail" placeholder="Usuario"/>
</div>
</div>
<div class="form-group">
<label class="control-label" for="inputPassword">Contraseña</label>
<div class="controls">
<input name="password" type="password" id="inputPassword" placeholder="Contraseña"/>
</div>
</div>
<div class="form-group">
<label class="checkbox">
<input type="checkbox" />Recordar</label>
<button type="submit" class="btn btn-info">Ingresar</button>
<a href="/">Registrar</a>
</div>
</form>
在這裏一切似乎都沒問題。顯示你的'app/notificaciones.html'。那麼'urls'呢? 'inclide'模塊只能插入html,而不是來自視圖的數據,所以你應該自己將它綁定到所需的模板。 – chem1st
@ Alfredhb.q你可以編輯你的文章向我們展示app/notificaciones.html和你的URLs.py文件嗎? – user2719875
@ user2719875完成後,我編輯了帖子,並顯示我的notificaciones.html和URLs.py –