"not all arguments converted during string formatting" Python Django

I am programming 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 1146, "The table" demo.home_userprofile "does not exist. Now I have 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 the Django page points to the not all arguments converted during string formatting error with me. This is a page that allows the user to upload an image and a phone number. What is the problem?

+4
source share
2 answers

Edit:

 ruta = "MultimediaData/Users/$s/%s"%(self.user.username, filename) 

To:

 ruta = "MultimediaData/Users/%s/%s"%(self.user.username, filename) # ^ Notice the sign change 

It seems you used $ instead of % , which was the problem.

+6
source

To make it compatible with Python 2 or 3 ...

 ruta = "MultimediaData/Users/{0}/{1}".format(self.user.username, filename) 
+2
source

All Articles