django-avatar表单位置问题

时间:2018-12-01 19:17:54

标签: python django

我是django / python的新手,并且正在使用django-avatar插件(https://github.com/grantmcconnaughey/django-avatar),因此用户可以将图像作为头像上传到我们的网站上。

我已经尝试调试此问题了一天,但不确定自己缺少什么。

我遇到的问题是,我将“ change.html”表单复制到了我们的myaccount.html页面中,并且得到了以下信息:

“您尚未上传头像。请立即上传。”

那是不正确的,因为我已经上传了一张图片,而我想要的只是带有输入字段的正确更改表单,一旦输入了头像就显示出来。当我希望其为“ / myaccount / change /”时,当我导航至“ / avatar / change /”时,我想要生成的表单会正确显示。

有人知道如何解决此问题吗?

谢谢!

myacccount.html

<p>{% trans "Your current avatar: " %}</p>
{% avatar user %} {% if not avatars %}
 <p>{% trans "You haven't uploaded an avatar yet. Please upload one now." %}</p>
 {% else %}
 {% endif %}
 <form enctype="multipart/form-data" method="POST" action="{% url 'avatar_add' %}">
 {{ upload_avatar_form.as_p }}
 <p>{% csrf_token %}
 <input type="submit" value="{% trans " Upload New Image " %}" />
 </p>
 </form>

views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import ListView
from .models import Post

from django.views.generic import TemplateView


# Create your views here.
def homePageView(request):
    return HttpResponse('Hello, World!');

class HomePageView(TemplateView):
    template_name = 'home.html'

class MyAccountView(TemplateView):
    template_name = 'myaccount.html'    

class AboutPageView(TemplateView):
    template_name = 'about.html'

class HomePageView(ListView):
    model = Post
    template_name = 'home.html'
    context_object_name = 'all_posts_list'

urls.py

# pages/urls.py
from django.urls import path
from django.urls import path, include
from django.conf.urls import url
from django.conf import settings

from .views import HomePageView, MyAccountView, AboutPageView

urlpatterns = [
    path('about/', AboutPageView.as_view(), name='about'),
    path('', HomePageView.as_view(), name='home'),
    path('myaccount/', MyAccountView.as_view(), name='myaccount'),
    url('avatar/', include('avatar.urls')),
]

1 个答案:

答案 0 :(得分:0)

没关系,只需更改文件位置设置即可,现在我可以正常使用了。谢谢。