应用程序创建一个分享知识的微博。
django-knowledge-share的Python项目详细描述
微博应用程序用来分享快速知识。这段代码加强了Vinta的经验教训 在http://www.vinta.com.br/lessons-learned/运行。
这些帖子是通过slack使用自定义命令创建的,并自动发布在twitter上。
快速启动
安装Django知识共享:
pip install django-knowledge-share
为您的微博创建应用程序:
python manage.py startapp microblog
将其添加到已安装的应用程序中
INSTALLED_APPS=(..."microblog","knowledge_share",...)
在urls.py中添加url条目:
url(r'^', include('knowledge_share.urls', namespace='microblog')),
在您的微博/models.py中,通过继承抽象模型来创建您的模型:
# customize those models as neededfromknowledge_shareimportmodelsasknowledge_share_abstract_modelsclassMicroBlogPost(knowledge_share_abstract_models.MicroBlogPostBase):passclassMicroBlogCategory(knowledge_share_abstract_models.MicroBlogCategoryBase):pass
然后创建并运行迁移:
python manage.py makemigrations python manage.py migrate
文档
型号
您可以看到可用的模型及其字段here。它们都是抽象的,您需要创建它的实例(请参阅快速启动部分)。
松弛积分
在此页中创建自定义命令:https://my.slack.com/services/new/slash-commands。
默认情况下,将url设置为松弛端点https://yoursite.com/microblog/integrations/slack-slash/ 复制生成的令牌并将其添加到settings.py中作为“slack_token=”your-token“。 要发送新邮件,请使用/yourcommand This is a blog post content [Category, Another Category]
Twitter集成
您需要使用twitter数据设置以下设置:
TWITTER_API_KEY TWITTER_API_SECRET TWITTER_ACCESS_TOKEN TWITTER_ACCESS_TOKEN_SECRET
无论何时创建新的帖子,它都会被发布到twitter上。
RSS源
默认情况下,在/microblog/feed/有一个rss提要。
配置
提供以下配置:
# settings.py# name of the app created with your microblog's modelsKNOWLEDGE_APP_NAME='microblog'# the title of the rss feed (available at: /microblog/feed/)KNOWLEDGE_FEED_TITLE='microblog'# the link of the feedKNOWLEDGE_FEED_LINK='/microblog/'# Either to use twitter or notKNOWLEDGE_USE_TWITTER=True
运行测试
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox