Python 获取forms.py的用户对象

Python 获取forms.py的用户对象,python,django,Python,Django,我有一个名为profiles的应用程序,它利用了django注册redux模块。我正在尝试创建一个表单,允许用户使用其中已有的信息对其进行编辑,但它没有显示出来。我可以让它在没有信息的情况下显示,但不能显示已经存在的配置文件信息 url.py from django.conf.urls import url from profiles import views urlpatterns = [ url(r'^(?P<username>[-\w]+)/$', views.sin

我有一个名为profiles的应用程序,它利用了django注册redux模块。我正在尝试创建一个表单,允许用户使用其中已有的信息对其进行编辑,但它没有显示出来。我可以让它在没有信息的情况下显示,但不能显示已经存在的配置文件信息

url.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"),
] 
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))
我收到的错误是:

异常值:以10为基数的int()的文本无效:“admin”


您需要检查
用户
模型的
用户名
字段

为此,请更换以下行:

instance = Profile.objects.get(user=username)
与:


您需要检查
用户
模型的
用户名
字段

为此,请更换以下行:

instance = Profile.objects.get(user=username)
与:


哪一行触发异常?
instance=Profile.objects.get(user=username)
哪一行触发异常?
instance=Profile.objects.get(user=username)
谢谢!这很有效,但我不能再接受10分钟的答复。你能解释一下
user\uu username
在做什么,或者给我指出正确的研究方向吗?@iampj,
user\uu username
是对
user
表的
username
字段进行查询。@iampj,我建议你阅读一下Making querys-Django文档。谢谢!这很有效,但我不能再接受10分钟的答复。您能解释一下
user\uu username
正在做什么,或者给我指出正确的研究方向吗?@iampj,
user\uu username
是对
user
表的
username
字段执行查询。@iampj,我建议您阅读《提出查询-Django文档》。