【发布时间】:2016-01-19 12:59:34
【问题描述】:
嗯,我已经设计了一些东西,但我不确定如何实现 它。
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,不能插入视图中的数据,因此您应该自己将其绑定到所需的模板。 -
@Alfredhb.q 你能编辑你的帖子向我们展示 app/notificaciones.html 和你的 URLs.py 文件吗?
-
@user2719875 完成,我编辑了帖子并显示了我的 notificaciones.html 和 URLs.py
-
@Alfredhb.q 哪个 HTML 页面是 "" 写在?什么视图呈现 html 页面? (询问是因为您发布的视图 - notifi - 呈现 app/notificaciones.html,这与上面的模板不同)。
-
是 layout.html,我正在尝试在 layout.html 中调用 notificaciones.html
标签: javascript python html django django-models