use*_*968 0 django templates django-templates profiles django-profiles
我正在使用django-registration和django-profiles构建应用程序.在页面的任何地方我都有显示当前登录用户数据的部分(如名字和姓氏,使用如下的语法{{ user.first_name }}
),它工作正常.它是通过子页面模板完成的,这些模板扩展了一个带有HTML结构的主模板和提到的部分.
现在我尝试将用户图像(使用{{ profile.image }}
)添加到该部分,并且{{ profile }}
模板变量的可用性存在问题,但在以下页面中:
在settings.py我有:
AUTH_PROFILE_MODULE = 'intranet.UserProfile'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
)
Run Code Online (Sandbox Code Playgroud)
添加"django.contrib.auth.context_processors.auth",
到TEMPLATE_CONTEXT_PROCESSORS
不会改变任何东西.
models.py中的我的UserProfile类是:
class UserProfile(models.Model):
user = models.OneToOneField(User)
image = models.ImageField(upload_to=user_image_name,
blank=True, null=True, verbose_name='User photo')
Run Code Online (Sandbox Code Playgroud)
urls.py:
(r'^profiles/edit/', 'profiles.views.edit_profile', {'form_class': ProfileForm, }),
(r'^profiles/', include('profiles.urls')),
Run Code Online (Sandbox Code Playgroud)
所以其余部分默认设置在django-profiles urls.py文件中.
我希望能够在应用程序的 {{ profile }}
模板中的任何地方(不仅在配置文件页面上)使用模板变量,以便可以在由其他模板扩展的主模板中使用它.
请让我知道如何才能得到这个.任何帮助将非常感激.
我在版本1.3.1中使用Django,在版本0.7中使用django-registration,在版本0.2中使用django-profiles.
我想你想要的user.get_profile()
.
如果您正在使用RequestContext
并拥有auth
上下文处理器列表settings.py
,{{user.get_profile.image}}
请尝试查看它是否符合您的要求.
归档时间: |
|
查看次数: |
1223 次 |
最近记录: |