我在Windows Vista上使用Python 2.7在Django 1.5中编程。我正在尝试创建用户配置文件。但是,当我访问localhost:8000 / admin / home / userprofile时,我得到了1146,“表'demo.home_userprofile'不存在错误。现在我已进入models.py
:
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class userProfile(models.Model):
def url(self, filename):
ruta = "MultimediaData/Users/$s/%s"%(self.user.username, filename)
return ruta
user = models.OneToOneField(User)
photo = models.ImageField(upload_to = url)
telefono = models.CharField(max_length = 30)
def __unicode__(self):
return self.user.username
Django页面指向not all arguments converted during string formatting
错误。这是一个允许用户上传图片和电话号码的页面。什么似乎是问题?
答案 0 :(得分:6)
变化:
ruta = "MultimediaData/Users/$s/%s"%(self.user.username, filename)
要:
ruta = "MultimediaData/Users/%s/%s"%(self.user.username, filename)
# ^ Notice the sign change
您似乎使用了$
而不是%
,这就是问题所在。
答案 1 :(得分:2)
使其与Python 2或3兼容......
ruta = "MultimediaData/Users/{0}/{1}".format(self.user.username, filename)