この場合、index.html にユーザー モデルの拡張値を表示する際に問題が発生します。
ここに私のmodels.py
from django.db import models
from django.contrib.auth.models import User
def url(self,filename):
ruta = "MultimediaData/Users/%s/%s"%(self.user.username,filename)
return ruta
class userProfile(models.Model):
user = models.OneToOneField(User)
photo = models.ImageField(upload_to=url)
telefono = models.CharField(max_length=30)
email = models.EmailField(max_length=75)
def __unicode__(self):
return self.user.username
私のindex.html:
{% extends 'base.html' %}
{% block title %} Inicio - Bienvenidos {% endblock %}
{% block content %}
<p>Dracoin, el portal que facilitará tu vida</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: {{user.get_profile.telefono}}</p>
{% endif %}
{% endif %}
{% endblock %}
管理パネルでその情報を管理するのに問題はありませんが、インデックスでその情報を表示できません。{% if user.get_profile.xxxx %} の呼び出しに間違いがあると思いますが、解決できません。
何か見落としがありましたら、あらかじめお詫び申し上げます。
ありがとう!!