UNKNOWN
项目描述
另一个基于Hashids和简化字母表的短URL生成器。
为什么要简化字母表?
因为如果你要费心创建短URL,它需要易于阅读和听觉,而不必不断检查你是否读错或听错。
为什么使用Hashids?
因为假设你的模型主键是整数,这是一种在相对较小空间内编码元组的方法。当然,也可以使用 django.utils.http.int_to_base36。
使用方法
在你的settings模块中
INSTALLED_APPS = ( # ... 'urlbrevity', # ... )
在你的根urlconf中
from django.conf.urls import patterns, url, include import urlbrevity urlpatterns = patterns("", # ... url(r'redirect/', include(urlbrevity.redirects)), # Or if you don't want to redirect ... url(r'no_redirect/', include(urlbrevity.no_redirects)), # ... )
在你的模板中
{% load urlbrevity %} <a href="{% url 'urlbrevity:short' my_model_instance|hashid %}">...</a> or ... <a href="{{ my_model_instance|short_url }}">
在你的Python代码中
import urlbrevity obj = MyModel.objects.get(pk='...') encoded = urlbrevity.encode_model_instance(obj=obj) value = encoded.hash url = reverse('urlbrevity:short', kwargs={'encoded_value': value}) # or ... url2 = urlbrevity.short_url(obj) # to re-inflate ... obj_again = urlbrevity.decode_model_instance(value)
为什么要内部重定向?
因为移动设备是一个重要领域,即使在3G+连接上,重定向也是另一轮往返,可能会失败或变慢。如果可能的话,直接渲染预期输出更容易。
许可协议
django-urlbrevity 在简化BSD许可协议(也称为FreeBSD许可协议或2条款许可协议)的条款下可用
Copyright (c) 2014, Keryn Knight All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪一个,请了解更多关于 安装包 的信息。
源代码分发
django-urlbrevity-0.1.0.tar.gz (10.9 kB 查看哈希值)
构建分发
关闭
django-urlbrevity-0.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2dd081dac39ac6a8bc70849219770c34ff548065ad2a047af50ce086d1c24b42 |
|
MD5 | 62f097b04bf95be6ee75adf8d2b93c14 |
|
BLAKE2b-256 | f949a168d2f42db9039fdaaadb6d3ed425360cc2cbe6c668beb9d79da5b3dc1f |
关闭
django_urlbrevity-0.1.0-py2-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a66c7483dd8fa22ebd6e3743abeeab3d061af8dfbc0934cb62d321e5e84b094a |
|
MD5 | 7bc539824505415d616f82c493592cb6 |
|
BLAKE2b-256 | 3f2e7b9e98b204e2dd901cbdf5f3448e213a1a9847a3e0e6ef824eb7ffe6f49e |