slug

Non-unique term slugs, or anything else I can use to build specific pages and permalinks?

佐手、 提交于 2019-12-08 05:43:44
问题 My project is a directory of business listings. Individual listing URL looks as simple as domain.com/five-star-cars - something that WordPress handles out of the box. But I have a problem drilling into region-based archives. We need a specific URL structure for those. For example, if we want to show all listings in Ohio, we need domain.com/ohio - also simple. However, if we want to show all listings in Cleveland, Ohio and Cleveland, Nevada - we want to do this: domain.com/cleveland/oh domain

How to use Yii2 Sluggable Behavior?

巧了我就是萌 提交于 2019-12-08 05:24:54
问题 I have defined this behavior as per documentation instructions. public function behaviors() { return [ TimestampBehavior::className(), [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', ], ]; } In my config url manager I have defined custom rule like this: example.com/article/1 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'article/<id:\d+>/<slug>' => 'article/view', ], ], My view action is: public

Combining more than one slug in the url

自古美人都是妖i 提交于 2019-12-08 05:14:00
问题 I'm trying to use two slug for generate the urls of a type of post. My site is divided in category and everyone of these have one or more post. views.py def singlePost(request, slug_post): blogpost = get_object_or_404(BlogPost, slug_post=slug_post) context = {"blogpost": blogpost} return render(request, "blog/single_post.html", context) def singleCategory_postList(request, slug_category): category = get_object_or_404(Category, slug_category=slug_category) blogpost = BlogPost.objects.filter

Django slug url in perisan 404

守給你的承諾、 提交于 2019-12-08 02:43:47
问题 I have a django url: path('question/<slug:question_slug>/add_vote/', views.AddVoteQuestionView.as_view()) It work fine with english slug but when slug is persian something like this: /question/سوال-تست/add_vote/ django url throw 404 Not Found , is there any solution to catch this perisan slug url? EDIT: I'm using django 2.1.5. It work fine with this url: re_path(r'question/(?P<question_slug>[\w-]+)/add_vote/$', views.AddVoteQuestionView.as_view()) 回答1: This is an addition to Selcuk answer

Using Slugify in Django urls

北城以北 提交于 2019-12-08 01:36:03
问题 I'm trying to create SEO friendly urls where all spaces are replaced with a hyphen. This is how I'm 'slugifying' the URL by using slugify in Django templates <a href="{% url 'dj' dj_name=dj.name|slugify %}"> Here is my urls.py url(r'^top100/(?P<dj_name>[a-zA-Z0-9 \'&-]+)/$', views.dj, name='dj') This is my view def dj(request, dj_name): dj = DJ.objects.get(name=dj_name) dj_song_list = Song.objects.filter(artist=dj, duplicate=False).order_by('-votes', '-release_date') return render(request,

Wordpress multiple slugs for a Custom Post Type

不羁的心 提交于 2019-12-07 12:16:32
问题 A custom post type can be registered with one slug (e.g. products) register_post_type('products', $args); How can I add multiple slugs to the same Custom Post Type? website_address.com/en/products/ website_address.com/fr/produits/ website_address.com/it/prodotti/ 回答1: The rewrite argument for register_post_type() accepts an array. One of the array keys is slug . So you could i18n it like this: register_post_type( 'products', array ( 'rewrite' => array ( 'slug' => _x( 'products', 'URL slug',

slug field on flask

巧了我就是萌 提交于 2019-12-07 07:44:34
问题 I want to create a slug field stored in database. I searched and I found http://flask.pocoo.org/snippets/5/ but I'm having trouble integrating the code in my app. This is my modele.py : from unicodedata import normalize def slugfy(text, encoding=None, permitted_chars='abcdefghijklmnopqrstuvwxyz0123456789-'): if isinstance(text, str): text = text.decode(encoding or 'ascii') clean_text = text.strip().replace(' ', '-').lower() while '--' in clean_text: clean_text = clean_text.replace('--', '-')

Using Slugify in Django urls

扶醉桌前 提交于 2019-12-06 10:44:43
I'm trying to create SEO friendly urls where all spaces are replaced with a hyphen. This is how I'm 'slugifying' the URL by using slugify in Django templates <a href="{% url 'dj' dj_name=dj.name|slugify %}"> Here is my urls.py url(r'^top100/(?P<dj_name>[a-zA-Z0-9 \'&-]+)/$', views.dj, name='dj') This is my view def dj(request, dj_name): dj = DJ.objects.get(name=dj_name) dj_song_list = Song.objects.filter(artist=dj, duplicate=False).order_by('-votes', '-release_date') return render(request, 'hunt/dj.html', {'dj_song_list': dj_song_list, 'dj':dj} Now the %20 in the urls has changed to a - but I

Incrementing the slug by avoiding Integrity error in django models save method

送分小仙女□ 提交于 2019-12-06 09:45:18
问题 I have a model with two fields as below models.py class Publisher(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(max_length=150, unique=True) def save(self, *args, **kwargs): if not self.id and not self.slug: slug = slugify(self.name) try: slug_exits = Publisher.objects.get(slug=slug) if slug_exits: self.slug = slug + '_1' except Publisher.DoesNotExist: self.slug = slug super(Publisher, self).save(*args, **kwargs) Here i am creating a slug based on the name

Django slug url in perisan 404

安稳与你 提交于 2019-12-06 09:44:26
I have a django url: path('question/<slug:question_slug>/add_vote/', views.AddVoteQuestionView.as_view()) It work fine with english slug but when slug is persian something like this: /question/سوال-تست/add_vote/ django url throw 404 Not Found , is there any solution to catch this perisan slug url? EDIT: I'm using django 2.1.5. It work fine with this url: re_path(r'question/(?P<question_slug>[\w-]+)/add_vote/$', views.AddVoteQuestionView.as_view()) This is an addition to Selcuk answer given here to pass such language/unicode characters you have to Write some custom path converter Use re_path()