一个可重用的django应用程序,用于取消缩短url。
django-unshorten的Python项目详细描述
一个django应用程序,用于取消缩短 像bit.ly这样的url缩写。
安装
要使用此应用程序,您需要安装以下先决条件:
pip install Django
如果要安装pypi的最新稳定版本:
$ pip install django-unshorten
如果您有冒险精神并希望安装来自github的最新提交:
$ pip install -e git://github.com/bitmazk/django-unshorten.git#egg=unshorten
将unshorten添加到INSTALLED_APPS:
INSTALLED_APPS = ( ..., 'unshorten', )
将此应用程序连接到您的urls.py:
urlpatterns = [ url(r'^unshorten/$', include('unshorten.urls')), ]
您需要设置执行速率限制的类。 默认设置为:
UNSHORTEN_RATE_LIMIT_CLASS = 'unshorten.rate_limit.SimpleRateLimit'
这只会将每日api调用限制为以下设置,您必须 同时提供:
UNSHORTEN_DAILY_LIMIT = 5000
还需要提供UNSHORTEN_API_AUTH_CLASS的设置。 默认值为:
UNSHORTEN_API_AUTH_CLASS = 'unshorten.authentication.SimpleAuthentication'
这提供了简单的http身份验证和登录身份验证。
在服务器上,如果使用mod_wsgi,则需要将此添加到 httpd.conf:
WSGIPassAuthorization On
用法
安装之后,用户应该能够使用基本http调用api 身份验证和查询。请求的URL可能如下所示:
https://example.com/unshorten/api/v1/unshorten/?url=http%3A%2F%2Fbitmazk.com
下面是一个使用curl进行基本http身份验证的请求示例:
curl --user user@example.com:password123 "https://example.com/unshorten/api/v1/unshorten/?url=bit.ly%2FUn9Gns"
贡献
如果您想参与此项目,请执行以下步骤
# Fork this repository # Clone your fork mkvirtualenv django-unshorten make develop git co -b feature_branch master # Implement your feature and tests git add . && git commit git push -u origin feature_branch # Send us a pull request for your feature branch
为了运行测试,只需执行tox。这将安装两个新的 环境(适用于django 1.8和django1.9)并针对这两个环境运行测试 环境。