5

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?

1
  • I am getting this same error in Django 1.6, in one place but not another, in the same views.py file. I have stared at the % making sure it's not a $ in both places about a dozen times. Going nuts. :) I'll add here if I figure it out. Commented Apr 21, 2015 at 23:03

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

No it was just the '$' sign. Little mistakes like that.
4

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

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

1 Comment

Why the downvote? If you're going to downvote someone, at least give them the courtesy of why. There's absolutely nothing wrong with either my answer or @Volatility's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.