slug

Django Url, Slug for Detail Page

a 夏天 提交于 2019-12-17 23:26:22
问题 I'm having trouble configuring my url to display a detail view. Clicking on this link: <a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a> shows blog.html , when I thought it would show blog-detail.html . There are no errors and the browser bar says: example.com/blog/the-slug , yet still displays the html from blog.html , not blog-detail.html . Any ideas why? Thanks for your ideas. url: url(r'^blog/', 'myapp.views.blog', name='blog'), url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views

Generating unique slug in Django

北慕城南 提交于 2019-12-14 01:11:54
问题 I have seen a variety of different methods for generating unique slugs: Ex. 1, Ex.2, Ex. 3, Ex. 4, etc. etc. I want to create unique slugs upon saving a ModelForm. If my models are like: class Phone(models.Model): user = models.ForeignKey(User) slug = models.SlugField(max_length=70, unique=True) year = models.IntegerField() model = models.ForeignKey('Model') series = models.ForeignKey('Series') Say that the Phone object has the following values (via submitted ModelForm): Phone.user = dude

when to store slugfield in database in django?

蓝咒 提交于 2019-12-13 19:23:52
问题 Suppose I access article at /article/23/the-46-year-old-virgin in /article/id/slug form. I can obviously use id to fetch the data in the view. Then I don't see a reason I would store the slug in a database. besides, /article/id/slug isn't better than /article/slug ? 回答1: The problem with only using the id is that it will hurt both URL readability and search engine optimization. (See here for the latter.) One problem with only using the slug is that they are long and URLs sometimes get

Django: Attribute error on custom Save()

爱⌒轻易说出口 提交于 2019-12-13 05:33:17
问题 I am having an issue creating a custom slug for the protocol model below. The custom save function to create the slug works fine with I do in the Admin page but not when I use the add_protocol view below. The Study model has a field called protocolnumber so I am not sure why it thinks it does not. I think it has something to do with how the view is set up, i.e. the commit = false and then the commit=true . Maybe because on the commit = False it is trying to assign a slug value using info from

Laravel routing, slug with multiple possibilities

╄→гoц情女王★ 提交于 2019-12-13 03:47:38
问题 Been searching for a while and can't find an answer on if this is possible. One URL I am trying to make. would be /location/province-name/city/category The province name only has a few options. Is there a way to set it up so something like this would work? /{bc or ab or mn or etc}/{cityname}/{category} does this make sense? 回答1: What you can do is use a pattern routes/web.php Route::pattern('province', '(bc|ab|mn|etc)'); Route::get('/location/{province}/{city}/{category}', function ($province

Mongoid_slug Rails 4 update / destroy object

痞子三分冷 提交于 2019-12-13 02:30:08
问题 I am using mongoig_slug gem in my rails app. I can create an object with the proper url but I can't update / delete the object and I have no error message in the console. (I can edit the form, which contains the correct data) I even used PRY to check in the console and when I check @book exits and is correct, if I do @book.destroy it says true but does not destroy. For the edit, I also checked @book, I also checked book_params which is correct. class Book include Mongoid::Document include

Regenerating slug Doctrine2

拈花ヽ惹草 提交于 2019-12-13 00:35:33
问题 I'm trying to regerate slug for entities that I've created prior to install Sluggable extension for Doctrine2 as it's explained here: Regenerating slug, but when I set it to empty string or null, does not regerate it, it simply sets as null. What I'm doing wrong? The entity: use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Gedmo\Mapping\Annotation as Gedmo; /** * @ORM\Entity * @ORM\Table(name="product") */ class Product { /** * @ORM\Id * @ORM\Column

Sanitizing Unicode strings for URL slugs (Ruby/Rails)

大城市里の小女人 提交于 2019-12-13 00:28:45
问题 I have UTF-8 encoded post titles which I'd rather show using the appropriate characters in slugs. An example is Amazon Japan's URL here. How can any arbitrary string be converted to a safe URL slug such as this, with Ruby (or Rails)? (There are some related PHP posts, but nothing I could find for Ruby.) 回答1: From reading here it seems like a solution is this: require 'open-uri' str = "\x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a".force_encoding('ASCII-8BIT'

django prepopulated fields break with hyphens

≯℡__Kan透↙ 提交于 2019-12-13 00:18:44
问题 I started putting prepopulated_fields options in my admins and funny stuff started happening I have this model class Pelicula(models.Model): nombre = models.CharField(max_length=50) slug = models.SlugField(max_length= 15, unique= True, help_text = "Nombre corto para la URL", primary_key= True) and this in admin.py class PeliculaAdmin(admin.ModelAdmin): prepopulated_fields = {'slug' : ['nombre']} nothing fancy, it's described all over the place But as soon as I use this slug in an object

How to get a slug name for a page without creating an admin page menu

ⅰ亾dé卋堺 提交于 2019-12-12 15:32:28
问题 I now use the add_submenu_page() function, but I don't want the edit page to appear in the admin menu. I want to access the edit page from a list (another page) directly. But I need the slug as a hook_suffix. I have in my-edit.php /* Set up the administration functionality. */ add_action( 'admin_menu', 'my_edit_setup' ); function my_edit_setup() { ... /* Add Edit Actionlist page. */ $myplugin->my_edit = add_submenu_page( 'myplugin', esc_attr__( 'Edit', 'myplugin' ), esc_attr__( 'Edit',