我创建一个Django应用程序与用户,我创建了我自己的UserProfile模型..但我有一些问题与我的网址(至少我认为)。我认为我使用的正则表达式是错误的。检查出来:Django的Url错误:无效的文字为int()与基地10:'托尼'
错误,我得到:
ValueError at /usr/tony/
invalid literal for int() with base 10: 'tony'
我的网址:
url(r'^usr/(?P<username>\w+)/$', 'photocomp.apps.users.views.Userprofile'),
我的观点:
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib import auth
from django.http import HttpResponseRedirect
from photocomp.apps.users.models import UserProfile
def Userprofile(request, username):
rc = context_instance=RequestContext(request)
u = UserProfile.objects.get(user=username)
return render_to_response("users/UserProfile.html",{'user':u},rc)
这里是我的模型:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
first_name = models.CharField(max_length="30", blank=True)
last_name = models.CharField(max_length="30", blank=True)
email = models.EmailField(blank=True)
country = models.CharField(blank=True,max_length="30")
date_of_birth = models.DateField(null=True)
avatar = models.ImageField(null=True, upload_to="/avatar")
非常感谢!初学者问题:) –