slug

Better to save a slug to the DB or generate dynamically?

最后都变了- 提交于 2019-12-04 08:57:40
I am working on a django project and would like to include a slug at the end of the url, as is done here on stackoverflow.com: http://example.com/object/1/my-slug-generated-from-my-title The object ID will be used to look up the item, not the slug -- and, like stackoverflow.com, the slug won't matter at all when getting the link (just in displaying it). Qestion : is there a downside (or upside) to generating the slug dynamically, rather than saving it as an actual database field ? For example (not real code): class Widget(models.Model): title = models.CharField() def _slug(self): return

wordpress: how to check if the slug contains a specific word?

梦想与她 提交于 2019-12-04 07:31:22
I'm trying to use a conditional statement to check if either of two words (blog & news) appear in the slug. If one shows up I will display one menu, if the other then its corresponding menu shows. Using PHP: $url = $_SERVER["REQUEST_URI"]; $isItBlog = strpos($url, 'blog'); $isItNews = strpos($url, 'news'); if ($isItBlog!==false) { //url contains 'blog' } if ($isItNews!==false) { //url contains 'news' } http://www.php.net/manual/en/function.strpos.php slugContainsBlog = "blog" if(window.location.href.indexOf(slugContainsBlog) > -1) { //Contains Blog } slugContainsNews = "news" if(window

Make a post slug unique

左心房为你撑大大i 提交于 2019-12-04 06:07:59
I got few functions in placed which is not working as I wanted. The slug is automicatlly created on the fly depend on the post title. Example: If a post title is "test" then the slug will be "test" My problem is that, what if theirs duplicate entry of post title "test" which means that the slug will be duplicated too. For that reason I have create 2 functions to handle this for me. This function checks if the slug exist in the database function slug_exist($x){ global $db; $sql = "SELECT post_name FROM posts WHERE post_name=\"$x\""; $query = $db->select($sql); if($db->num_rows() > 0){ return

Skip saving row if slug already exists in postgresql database - python

允我心安 提交于 2019-12-04 06:05:27
问题 I'm setting up a function in my Django Views that calls an API and save the data into my Postgresql database. Everthing was working fine until I got an IntegrityError slugkey already exists, so I'm trying to find a way to skip or ignore the row if the slugify slug already exists. I've been stuck with this all day and I need a solution to respect expected timeline.. This is my Django Models: class Product(models.Model): destination = models.CharField(max_length=255, default='') title = models

How can I make URLs in Django similar to stackoverflow?

冷暖自知 提交于 2019-12-04 05:58:05
I'm creating a video site. I want my direct urls to a video to look like example.com/watch/this-is-a-slug-1 where 1 is the video id. I don't want the slug to matter though. example.com/watch/this-is-another-slug-1 should point to the same page. On SO, /questions/id is the only part of the url that matters. How can I do that? Stack Overflow uses the form example.com/watch/1/this-is-a-slug which is easier to handle. You're opening a can of worms if you want the ID to be at the end of the slug token, since then it'll (for example) restrict what kinds of slugs you can use, or just make it harder

creating unique page title slugs php

一笑奈何 提交于 2019-12-04 05:15:12
I have a function for creating unique slug for a page title. It checks if the slug is available in the pages table then creates a unique slug by adding a '-int' accordingly. The function works fine for the first three entries eg for 'test slug' entered three time will create 'test-slug-1', 'test-slug-2' and 'test-slug-3'. Then after that I get an error "Fatal error: Maximum execution time of 30 seconds exceeded" for the fourth entry. There should be some problem with the logic, can anyone help me find it please.Below is the code: function createSlug($title, $table_name, $field_name) { global

Extract first URL Segment from full URL

感情迁移 提交于 2019-12-04 04:32:06
How can the first URL segment be extracted from the full URL? The first URL segment should be cleaned to replace the - with a space . Full URL http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020 Desired Outpput River Island You can use: $url = 'http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020'; $parsed = parse_url($url); $path = $parsed['path']; $path_parts = explode('/', $path); $desired_output = $path_parts[1]; // 1, because the string begins with slash (/) $page =

How to enable arabic slug in htaccess?

我的梦境 提交于 2019-12-04 02:15:31
问题 I have a multi-languages website, and I'm trying to create a friendly URL. In my database, I have the slug field. When the article's title is in english the slug appear in url and redirection works fine. but when the title is arabic the slug appear and the redirection shows " Object not found " page. what seems to be the problem guys ? please help I'm stack. 回答1: Most likely the issue is your rewriting rule. It explicitly is crafter such that it only gets applied for requests that consist of

Django: Slug in Vietnamese

一个人想着一个人 提交于 2019-12-03 20:27:08
问题 A site in Vietnamese, it is virtually no different to English. However, there is a problem that is slug. When I type characters such as "ư", "ơ", "á",... Django is not identified. Solution here is to replace characters that do not sign into. Eg: ư -> u ơ -> o á -> a One from "những-viên-kẹo" will become "nhung-vien-keo". However, I do not know how to do this. Someone help me. Thank you very much! 回答1: [edit] I take it back, django's django.template.defaultfilters.slugify() does what you want,

Validating a slug in Django

和自甴很熟 提交于 2019-12-03 13:16:54
I'm guessing this is going to involve regexp or something, but I'll give it a shot. At the minute, a user can break a website by typing something similar to £$(*£$(£@$&£($ in the title field, which is converted into a slug using Django slugify . Because none of these characters can be converted, Django returns an error. My question is, what should I put in the form validation method to raise a forms.ValidationError when the user uses a title like this? Thanks. This question is half a decade old so in updating my question I should explain that I'm at least nodding to the past where some