我有一个名为profiles的应用程序,它利用了django registration redux模块。我正在尝试创建一个表单,允许用户使用其中已有的信息对其进行编辑,但它没有显示出来。我可以让它在没有信息的情况下显示出来,但不能显示已经存在的配置文件信息。你知道吗
网址.py
from django.conf.urls import url
from profiles import views
urlpatterns = [
url(r'^(?P<username>[-\w]+)/$', views.single, name='profile_single'),
url(r'^(?P<username>[-\w]+)/edit/$', views.edit, name="profile_edit"),
]
视图.py
def edit(request, username):
instance = Profile.objects.get(user=username)
# It would be good to have an in depth understanding of what the actual request module does
if request.user == instance.user:
form = ProductForm(request.POST or None, instance = instance)
if form.is_valid():
profile = form.save(commit=False)
profile.user = request.user
profile.slug = slugify(form.cleaned_data['title'])
profile.save()
return HttpResponseRedirect('/user/%s'%(user.username))
return render_to_response("profiles/edit.html", locals(), context_instance=RequestContext(request))
我收到的错误是:
Exception Value: invalid literal for int() with base 10: 'admin'
您需要检查
username
模型的User
字段。你知道吗为此,请替换以下行:
使用:
相关问题 更多 >
编程相关推荐