我正在用Windows Vista上的Python 2.7在Django 1.4.3中进行编程。我正在尝试为用户输入功能,例如localhost:8000/admin
中的电话,然后显示在前面的网页上。我有index.html
用于前页面:显示值Django Python
<!-- 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
然而,经过I输入的telefono
(电话)值,前页不显示它。我附上了我收到的头版。该数字应显示在鱼片图像下。什么似乎是问题?
你能后的HTML输出,所以我们可以看到被呈现? – Nitzle 2013-03-18 01:21:14
此外,由于您使用的是Django 1.5,您应该知道'get_profile'方法已被[弃用](https://docs.djangoproject.com/en/1.5/releases/1.5/#auth-profile-module) 。 – Nitzle 2013-03-18 01:24:15
大家好。我没有编辑正确的HTML和PY文件。我只是迁移了我的工作目录,但Notepad ++仍然有这些文件的记录。问题解决了。电话现在显示。感谢所有帮助过的人。 – Dombey 2013-03-18 04:46:37