Django-slug-preview - PyPI
pip install django-slug-preview Copy PIP instructions
Latest versionReleased: Jan 6, 2022
An advanced slug field with URL previews.
Navigation
- Project description
- Release history
- Download files
Verified details
These details have been verified by PyPIMaintainers
Unverified details
These details have not been verified by PyPIProject links
- Homepage
- Download
Meta
- License: Apache Software License (Apache 2.0)
- Author: Diederik van der Boor
Classifiers
- Development Status
- 4 - Beta
- Environment
- Web Environment
- Framework
- Django
- Django :: 2.2
- Django :: 3.1
- Django :: 3.2
- Django :: 4.0
- Intended Audience
- Developers
- License
- OSI Approved :: Apache Software License
- Operating System
- OS Independent
- Programming Language
- Python
- Python :: 3
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Topic
- Internet :: WWW/HTTP
- Software Development :: Libraries :: Python Modules
- Project description
- Project details
- Release history
- Download files
Project description
django-slug-preview
An advanced slug field offering live URL previews.
This is inspired by the “Permalink” preview that WordPress offers. While not looking as fancy yet, this is a good start for Django projects. Improvements are welcome!
Installation
First install the module, preferably in a virtual environment. It can be installed from PyPI:
pip install django-slug-previewOr the current folder can be installed for development:
pip install -e .Add slug_preview to your INSTALLED_APPS:
INSTALLED_APPS += ( 'slug_preview',)Usage
Use slug_preview.models.SlugPreviewField in your models instead of the standard models.SlugField.
Add slug_preview.forms.SlugPreviewFormMixin in your forms.
For example:
from django.db import modelsfrom slug_preview.models import SlugPreviewFieldclass MyModel(models.Model): slug = SlugPreviewField(_("Slug"))In the admin you can use the SlugPreviewModelForm shortcut:
from django.contrib import adminfrom django import formsfrom slug_preview.forms import SlugPreviewModelForm@admin.register(MyModel)class MyModelAdmin(admin.ModelAdmin): form = SlugPreviewModelFormIn custom forms, use SlugPreviewFormMixin directly:
from django import formsfrom slug_preview.forms import SlugPreviewFormMixinfrom .models import MyModelclass MyModelForm(SlugPreviewFormMixin, forms.ModelForm): class Meta: model = MyModelSpecial model URLS
When a model has a custom URL layout (not just /{slug}/), you can add a get_absolute_url_format() method in the model. For example:
from django.db import modelsfrom slug_preview.models import SlugPreviewFieldclass Page(models.Model): parent = models.ForeignKey('self') slug = SlugPreviewField(_("Slug")) # ... def get_absolute_url(self): if self.parent_id: return "{0}{1}/".format(self.parent.get_absolute_url(), self.slug) else: return "/{0}/".format(self.slug) def get_absolute_url_format(self): if self.parent_id: return "{0}{{slug}}/".format(self.parent.get_absolute_url()) else: return "/{slug}/"For a blog, you can add the /blog/{year}/{month}/ format too:
from django.core.urlresolvers import reversefrom django.db import modelsfrom django.utils.timezone import nowfrom slug_preview.models import SlugPreviewFieldclass Article(models.Model): slug = SlugPreviewField(_("Slug")) pubdate = models.DateTimeField(default=now) # ... def get_absolute_url(self): root = reverse('article_list') return "{root}/{year}/{month}/{slug}/".format( root=reverse('article_list').rstrip('/'), year=self.pubdate.strftime('%Y'), monthy=self.pubdate.strftime('%M'), slug=self.slug ) def get_absolute_url_format(self): root = reverse('article_list') pubdate = self.pubdate or now() return "{root}/{year}/{month}/{{slug}}/".format( root=reverse('article_list').rstrip('/'), year=pubdate.strftime('%Y'), monthy=pubdate.strftime('%M'), )Improving this package
This module is designed to be usable for other projects too. In case there is anything you didn’t like about it, or think it’s not flexible enough, please let us know. We’d love to improve it! Pull requests are welcome too. :-)
Project details
Verified details
These details have been verified by PyPIMaintainers
Unverified details
These details have not been verified by PyPIProject links
- Homepage
- Download
Meta
- License: Apache Software License (Apache 2.0)
- Author: Diederik van der Boor
Classifiers
- Development Status
- 4 - Beta
- Environment
- Web Environment
- Framework
- Django
- Django :: 2.2
- Django :: 3.1
- Django :: 3.2
- Django :: 4.0
- Intended Audience
- Developers
- License
- OSI Approved :: Apache Software License
- Operating System
- OS Independent
- Programming Language
- Python
- Python :: 3
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Topic
- Internet :: WWW/HTTP
- Software Development :: Libraries :: Python Modules
Release history Release notifications | RSS feed
This version2.0.1
Jan 6, 2022
2.0
Nov 16, 2021
1.0.5
Apr 1, 2021
1.0.4
Feb 12, 2018
1.0.3
Feb 12, 2018
1.0.2
Dec 30, 2016
1.0.1
Feb 7, 2016
1.0
Dec 30, 2015
0.9
Aug 20, 2015
0.9.dev0 pre-release
Aug 20, 2015
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-slug-preview-2.0.1.tar.gz (11.1 kB view details)Uploaded Jan 6, 2022 Source
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters Copy
File name Interpreter Interpreter py3 ABI ABI none Platform Platform any django_slug_preview-2.0.1-py3-none-any.whl (12.5 kB view details)Uploaded Jan 6, 2022 Python 3
File details
Details for the file django-slug-preview-2.0.1.tar.gz.
File metadata
- Download URL: django-slug-preview-2.0.1.tar.gz
- Upload date: Jan 6, 2022
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 54967848101ffd241321e3373b4675d98a40e683c0c54b7d7efbfb2c653d2bf9 | Copy |
| MD5 | 8117ec165427a5b43dfa6dd5e64abe54 | Copy |
| BLAKE2b-256 | 90ca8c80606da33dcb8b0658f8b139ee3dacc618a889d881c88229bd92b75088 | Copy |
See more details on using hashes here.
File details
Details for the file django_slug_preview-2.0.1-py3-none-any.whl.
File metadata
- Download URL: django_slug_preview-2.0.1-py3-none-any.whl
- Upload date: Jan 6, 2022
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 87e69df096534be417f9f5296d1a8d256bc6eeac608ada899920ff9c751ba57f | Copy |
| MD5 | ef4bf80b80f4e78370da2ba54b25f24a | Copy |
| BLAKE2b-256 | 359dcb76d4cd8c520c1523e3b512a7f248182c96f42e0b4709585c7a8eaa58f6 | Copy |
See more details on using hashes here.
- English
- español
- français
- 日本語
- português (Brasil)
- українська
- Ελληνικά
- Deutsch
- 中文 (简体)
- 中文 (繁體)
- русский
- עברית
- Esperanto
- 한국어
Supported by
Từ khóa » đan Slug
-
What Is A "slug" In Django? - Stack Overflow
-
Django Slug Tutorial
-
Add The Slug Field Inside Django Model - GeeksforGeeks
-
43 - Slugs In Dynamic Urls - Python & Django 3.2 Tutorial Series
-
Using Translated Slugs In Views — Django-parler 2.3 Documentation
-
Slug Field Is Accepting Whitespace When Entered Through Django Shell.
-
URL Dispatcher - Django Documentation
-
Marcanuy/django-slugs-example-app: A Basic App To Show ... - GitHub
-
Changing Page Settings — Django Cms 3.4.7 Documentation
-
Slug In Django | Delft Stack
-
12. How To Use Slug Field With Django For More Readability?
-
Installation — Django-primary-slug V0.1.1b1 Documentation
-
Dan Slug | Facebook