我正在 Windows Vista 上使用 Python 2.7 在 Django 1.4.3 中进行编程。我正在尝试在 localhost:8000/admin
中输入用户的功能,例如电话,然后显示在前端网页上。我的首页有 index.html
:
<!-- Shows the label on tab. -->
{% block title %} Inicio - Bienvenidos {% endblock %}
{% block content %}
<p> Esta es mi primera pagina en Django </p>
{% if user.is_authenticated %}
<p> Bienvenido {{user.username}} </p>
{% if user.get_profile.photo %}
<img src="/media/{{user.get_profile.photo}}" width="100px" height="100px"/>
{% endif %}
{% if user.get_profile.telefono %}
<p> Numero Tel:</p> {{user.get_profile.telefono}}</p>
{% endif %}
{% endif %}
{% endblock %}
它正在提取 models.py
中定义的输入值:
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class userProfile(models.Model):
def url(self, filename):
ruta = "MultimediaData/Users/%s/%s"%(self.user.username, filename)
return ruta
user = models.OneToOneField(User)
photo = models.ImageField(upload_to = url)
telefono = models.CharField(max_length = 30)
def __unicode__(self):
return self.user.username
但是,当我输入telefono
(电话)值后,首页不显示它。我已附上我收到的首页。该数字应出现在鱼片图像下方。问题出在哪里?
最佳答案
看起来您已经注释掉了该值。 <!--
和-->
被视为 HTML 中的注释。
从技术上讲,django 模板仍在呈现该值,因为它们使用不同的注释格式,但您的浏览器会看到注释标记,然后隐藏内容。
更改此行:
<p> Numero Tel:</p> <!--{{user.get_profile.telefono}}</p>-->
对此:
<p> Numero Tel:</p> {{user.get_profile.telefono}}</p>
关于python - 显示值 Django Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15468281/