I am programming in Django 1.5 with Python 2.7 on Windows Vista. I am trying to create user profiles. However, when I visit localhost:8000/admin/home/userprofile, I got the 1146, "Table 'demo.home_userprofile' doesn't exist error. Now I have in 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
And Django page is pointing not all arguments converted during string formatting
error at me. This is a page that allows user to upload picture and phone number. What seems to be the problem?
Such a common error is TypeError: not all arguments converted during string formatting. This error is caused when there is a mismatch in data types and strings are not properly formatted. The solution to this error is to use proper string formatting functions such as int() or str() to obtain the desired data type.
The “not all arguments converted during string formatting” error is raised when Python does not add in all arguments to a string format operation. This happens if you mix up your string formatting syntax or if you try to perform a modulo operation on a string.
To use formatted string literals, begin a string with f or F before the opening quotation mark or triple quotation mark. Inside this string, you can write a Python expression between { and } characters that can refer to variables or literal values.
Change:
ruta = "MultimediaData/Users/$s/%s"%(self.user.username, filename)
To:
ruta = "MultimediaData/Users/%s/%s"%(self.user.username, filename)
# ^ Notice the sign change
You seem to have used a $
instead of a %
, which was the problem.
To make it compaitble with Python 2 or 3...
ruta = "MultimediaData/Users/{0}/{1}".format(self.user.username, filename)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With