Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Not Getting It Right #11

Closed
skizzy opened this issue Feb 17, 2012 · 6 comments
Closed

Error: Not Getting It Right #11

skizzy opened this issue Feb 17, 2012 · 6 comments

Comments

@skizzy
Copy link

skizzy commented Feb 17, 2012

Hello, I’m not getting the usage of the package in template, because I keep getting error. What I did is this; I want to use it for following of users. Just like how friends add each other up or follow each other on sites like twitter.
So I registered it with UserProfile in models,py.

utils.register(UserProfile)

And UserProfile consists of fields like names, state, country, etc.

After registering it in models, I went on to profiles template and ‘include /follow/form.html’ so that if a user finds another users profile, and both are not following each other, it will be easy for one of them to make the request by following. But I keep getting error.

My question now is this: How will I make use of it in the template? What is the best way of doing this? Hope to hear from you soon. Thanks!

@flashingpumpkin
Copy link
Contributor

Hi

You shouldn't include the form but use the template tags provided:

{% load follow_tags %}
{% follow_form request.user.profile %}

That should make it work.

@flashingpumpkin
Copy link
Contributor

(Obviously you'd have to adjust the request.user.profile object to fit your needs and models.)

@skizzy
Copy link
Author

skizzy commented Feb 22, 2012

I’m still not getting it bro! I’m getting this error:

TemplateSyntaxError at /profiles/Lordme/
Caught VariableDoesNotExist while rendering: Failed lookup for key [UserProfile] in u'picomon'
Request Method: GET
Request URL:    http://127.0.0.1:8000/profiles/Lordme/
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:    Caught VariableDoesNotExist while rendering: Failed lookup for key [UserProfile] in u'picomon'
Exception Location: C:\Python27\lib\site-packages\django\template\base.py in _resolve_lookup, line 692
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.2

This is what I did.

In Models:

class UserProfile(models.Model):
    user=models.ForeignKey(User, unique=True)
    avatar=models.ImageField("Profile Pic", upload_to="photologue/photos/", blank=True, null=True)
    names=models.CharField(max_length=50)
    country=models.CharField(max_length=50)
    state_province=models.CharField(max_length=50)
    url=models.URLField('Website', blank=True)
    bio=models.TextField(max_length=1000)
    objects=ProfileManager()

    def __unicode__(self):
        return u"%s" % self.user
    def get_absolute_url(self):
        return ('profiles_profile_detail',(),{'username':self.username})
utils.register(UserProfile)

In follow/form.html

{% load follow_tags %}
<form action="{% follow_url UserProfile %}" method="POST">
    {% csrf_token %}
    {% if request.user|is_following:UserProfile %}
        <input type="submit" value="Unfollow" />
    {% else %}
        <input type="submit" value="Follow" />
{% endif %}
</form>

In profiles/profile_detail.html

{% load follow_tags %}
    {% follow_form request.user.UserProfile %}

What am I doing wrong? UserProfile is the object.

@flashingpumpkin
Copy link
Contributor

The VariableNotFound error suggests that request.user.UserProfile does not exist. Also your code suggests that you're trying to access the UserProfile class on the User model instead of following the ForeignKey relationship back. You should also have a look at related_name to make this all a bit easier.

Fix

Try setting the AUTH_PROFILE_MODULE setting and then do

{% load follow tags %}
{% follow_form request.user.get_profile %}

@flashingpumpkin
Copy link
Contributor

Also, don't modify the form.html unless you know what you're doing.

@flashingpumpkin
Copy link
Contributor

(You seem to be assuming that the UserProfile model is automagically arriving at the template. It's not. An instance of it will though, when you either use get_profile like described above, or request.user.user_profile_set.all.0 without setting the AUTH_PROFILE_MODULE and without setting a related_name.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants