我正在使用 django-registration 和 django-profiles 构建应用程序。在页面的任何地方,我都有显示当前登录用户数据的部分(如名字和姓氏,使用类似的语法:){{ user.first_name }}
,它工作正常。它是通过子页面模板来完成的,该模板扩展了一个具有 HTML 结构的主模板和提到的部分。
现在我尝试将用户图像(使用)添加到该部分,但在以下页面上到处都{{ profile.image }}
存在模板变量的可用性问题:{{ profile }}
- http://127.0.0.1:8000/profiles/myusername/(myusername是有头像的人的用户名),
- http://127.0.0.1:8000/profiles/edit/。
在settings.py我有:
AUTH_PROFILE_MODULE = 'intranet.UserProfile'
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
)
添加"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')
urls.py:
(r'^profiles/edit/', 'profiles.views.edit_profile', {'form_class': ProfileForm, }),
(r'^profiles/', include('profiles.urls')),
所以其余的默认设置在django-profiles urls.py文件中。
我希望能够在应用程序模板中的 {{ profile }}
任何地方(不仅在配置文件页面上)使用模板变量,以便可以在其他人扩展的主模板中使用它。
请让我知道我怎样才能得到这个。任何帮助将不胜感激。
我在 1.3.1 版中使用 Django,在 0.7 版中使用 django-registration,在 0.2 版中使用 django-profiles。