Comments (6)
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.
(Obviously you'd have to adjust the request.user.profile
object to fit your needs and models.)
from django-follow.
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.
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.
Also, don't modify the form.html
unless you know what you're doing.
from django-follow.
(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)
- TemplateSyntaxError
- TemplateSyntaxError
- TemplateSyntaxError HOT 4
- Targeting Userprofile
- model field error HOT 3
- Django 1.5 Compatibility for Configurable User HOT 5
- Support for AJAX follow / unfollow. HOT 2
- Unicode decode error HOT 2
- Add model_name instead of put all models as columns
- Foreign key constraints not created
- Example of getting following
- Incompatible with django 1.8 HOT 1
- Problem with higher django version
- Is this package working with Django 2.2?
- Incorrect documentation (FollowManager classmethods) HOT 1
- TemplateSyntaxError HOT 4
- Typo in template HOT 1
- Issue installing on Windows
- Unicode error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-follow.