Get_Next_by_Date()返回Post的名称而不是它的url

时间:2016-12-05 20:44:28

标签: django

我有一个类似应用程序的博客,我正在尝试为Blog的每个帖子实现一个NEXT按钮。 我目前正在使用Detail_View来显示每个帖子。

在模板中,我正在使用

LoadError on line ["55"] of /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb: cannot load such file -- compass-h5bp
  /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/lib/compass/configuration/data.rb:179:in `require'
  /Users/paulnicholsen/industry/divesite-docker/socialmediatoday/sites/all/themes/smtrelaunch/config.rb:2:in `get_binding'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/serialization.rb:24:in `eval'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/serialization.rb:24:in `parse_string'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/serialization.rb:15:in `block in _parse'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/serialization.rb:14:in `open'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/serialization.rb:14:in `_parse'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/file_data.rb:7:in `block in new_from_file'
  /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.3/lib/compass/configuration/inheritance.rb:207:in `with_defaults'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/file_data.rb:6:in `new_from_file'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/helpers.rb:19:in `configuration_for'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/configuration/helpers.rb:69:in `add_project_configuration'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/project_base.rb:37:in `add_project_configuration'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/project_base.rb:25:in `configure!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/project_base.rb:15:in `initialize'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/commands/update_project.rb:41:in `initialize'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/exec/sub_command_ui.rb:42:in `new'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/exec/sub_command_ui.rb:42:in `perform!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/lib/compass/exec/sub_command_ui.rb:15:in `run!'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:30:in `block in <top (required)>'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:44:in `call'
  /Library/Ruby/Gems/2.0.0/gems/compass-1.0.3/bin/compass:44:in `<top (required)>'
  /usr/local/bin/compass:23:in `load'
  /usr/local/bin/compass:23:in `<main>'

但是没有正确链接到下一篇文章,我所拥有的是一个指向博客的链接,其中包含帖子的名称而不是PK,如:

博客/帖子名称xy

关于如何解决问题的建议? 最好的问候。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

<a href="/blog/{{post.get_next_by_date.id}}/{{post.get_next_by_date.slug}}">NEXT BLOG PAGE</a>

它适用于通用视图“detail_view”