django活动流,我接近错了吗?

时间:2016-01-21 04:33:35

标签: python django

我使用django-activity-stream来关注/取消关注并显示关注/取消关注的内容。但作为一个noobie,文档似乎含糊不清。如果有人能弄清楚我做错了什么,我将非常感激。这是文档; https://django-activity-stream.readthedocs.org/en/latest/actions.html

这是我采取的步骤。

pip install django-activity-stream

然后在我的设置中添加了actstream并设置了actstream的url。 我还包括了网址,

url(r'^unfollow/(?P<category_name_url>\w+)/', 'main.views.unfollow_user', name='unfollow'),
    url(r'^follow/(?P<category_name_url>\w+)/', 'main.views.follow_user', name='follow'),

然后我在我的主app文件夹中创建了apps.py。

来自django.apps导入AppConfig 来自actstream import registry

from django.contrib.auth import get_user_model


class MyAppConfig(AppConfig):
    name = 'subs'

    def ready(self):
        registry.register(get_user_model())
        registry.register(self.get_model('Category'))

我试图关注类别模型,并显示该类别中的内容。

这里有models.py

    from actstream import action
    class Category(models.Model): 
        name = models.CharField(max_length=128, unique=True)
        description = models.CharField(max_length=200, unique=True)
        image = models.FileField(upload_to='images',blank=True, null=True)
        author = models.ForeignKey(settings.AUTH_USER_MODEL)

        def __unicode__(self): 
            return self.name

    def new_category(sender, instance, created, **kwargs):
        action.send(instance.user, verb='posted', target=instance, mood='sleepy')

    post_save.connect(new_category, sender=Category)

然后在views.py中,这是我摇摇欲坠的部分

def timeline(request):
    activities = user_stream(request.user)
    context = {
        'activities': activities,
    }
    return render(request, 'all_timeline.html', context)


def category_timeline(request, category_name):
    user = User.objects.select_related('profile').get(category_name=category_name)
    user_actions = []

    if is_following(request.user, user) or not user.profile.private:
        user_actions = actor_stream(user)

    context = {
        'user': user,
        'activities': user_actions,
    }
    return render(request, 'timeline.html', context)


def follow_user(request, category_name):
    follow(request.user, User.objects.get(category_name=category_name))
    return redirect('category_timeline', category_name)


def unfollow_user(request, category_name):
    unfollow(request.user, User.objects.get(category_name=category_name))
    return redirect('category_timeline', category_name)

在教程中,他们使用的是user_name,但由于我以下类别,我认为我必须将其更改为category_name ...这可能会使原来的actstream应用程序变得混乱? \如果我只是希望功能显示以下类别的内容,那么我不需要时间轴功能吗?

简而言之,当我进入follow / url时,我得到follow_user() got an unexpected keyword argument 'category_name_url' and it's occuring from env/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response, line 132所以我不知道发生了什么。也不确定我在做什么...... 这是我的追溯

env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

Exception Type: TypeError at /follow/aa/
Exception Value: follow_user() got an unexpected keyword argument 'category_name_url'

0 个答案:

没有答案