Git Product home page Git Product logo

Comments (6)

flashingpumpkin avatar flashingpumpkin commented on July 30, 2024

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.

from django-follow.

flashingpumpkin avatar flashingpumpkin commented on July 30, 2024

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

from django-follow.

skizzy avatar skizzy commented on July 30, 2024

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.

from django-follow.

flashingpumpkin avatar flashingpumpkin commented on July 30, 2024

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 %}

from django-follow.

flashingpumpkin avatar flashingpumpkin commented on July 30, 2024

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

from django-follow.

flashingpumpkin avatar flashingpumpkin commented on July 30, 2024

(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.)

from django-follow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.