微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

博客帖子django中的网址

如何解决博客帖子django中的网址

| https://github.com/nathanborror/django-basic-apps/blob/master/README.rst我正在尝试实现此博客模块,我的问题是我正在编写一个泛型函数,当我获取博客时得到一个网址为
def Myfunc(request):
  p = Post.objects.get(pk=12)
  p.get_absolute_url //This prints blog/2011/jun/13/fgfgf/
我的问题是,如何获取带有域名的url或在代码中在哪里处理。
EDIT: i.e,http://mysite.com/blog/2011/jun/13/fgfgf/
型号字段为
  class Post(models.Model):
      \"\"\"Post model.\"\"\"
      STATUS_CHOICES = (
          (1,_(\'Draft\')),(2,_(\'Public\')),)
      title = models.CharField(_(\'title\'),max_length=200)
      slug = models.SlugField(_(\'slug\'),unique_for_date=\'publish\')
      author = models.ForeignKey(User,blank=True,null=True)
      body = models.TextField(_(\'body\'),)
      tease = models.TextField(_(\'tease\'),help_text=_(\'Concise text suggested. Does not appear in RSS Feed.\'))
      status = models.IntegerField(_(\'status\'),choices=STATUS_CHOICES,default=2)
      allow_comments = models.BooleanField(_(\'allow comments\'),default=True)
      publish = models.DateTimeField(_(\'publish\'),default=datetime.datetime.Now)
      created = models.DateTimeField(_(\'created\'),auto_Now_add=True)
      modified = models.DateTimeField(_(\'modified\'),auto_Now=True)
      categories = models.ManyToManyField(Category,blank=True)
      #created_by = models.ForeignKey(UserProfile)
      tags = TagField()
      objects = PublicManager()

      class Meta:
          verbose_name = _(\'post\')
          verbose_name_plural = _(\'posts\')
          db_table  = \'blog_posts\'
          ordering  = (\'-publish\',)
          get_latest_by = \'publish\'

      def __unicode__(self):
          return u\'%s\' % self.title

      @permalink
      def get_absolute_url(self):
          return (\'blog_detail\',None,{
              \'year\': self.publish.year,\'month\': self.publish.strftime(\'%b\').lower(),\'day\': self.publish.day,\'slug\': self.slug
          })
    

解决方法

        您可以使用sites框架获取完全限定的url-按照https://docs.djangoproject.com/en/1.2/ref/contrib/sites/     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。