如何获取Django管理员的“现场查看”链接到工作? [英] How can I get the Django admin's "View on site" link to work?

查看:192
本文介绍了如何获取Django管理员的“现场查看”链接到工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Django应用程序一段时间,而Django管理界面的工作原理很好,除了,在网站上查看链接不起作用。每当我尝试使用它,我得到一个 OperationalError 与消息:没有这样的表:django_site 。我已经做了一些研究这个问题,似乎我必须设置 Django网站框架,这个链接工作,但我完全确定如何做到这一点。文档说明了数据库表等,但它并没有说明如何实际设置一个站点。所以我的问题真的是双重的:


  1. 如何让网站框架设置?我必须自己创建表(并自己输入数据),或者有什么我必须启用,所以 ./ manage.py syncdb 将自动检测我想要设置表?

  2. 当我在本地开发时,设置网站框架会影响我(即,只是在本地主机上运行,​​而不是关闭我的实际域名)?如果DEBUG else 1 ,或者$ $ c,我必须添加一些 settings.py ,如 SITE_ID = 2 $ c> manage.py 只是检测到我在调试站点上工作,而不是对站点框架做任何事情?


解决方案

放置

 'django.contrib.sites',

进入您的INSTALLED_APPS和以下

  $ ./manage.py syncdb 

可能就够了。 >

安装后,编辑Site实例(例如通过 / admin 界面)来反映您的本地主机名(例如 localhost:8000 )。


I've been working with a Django app for a while, and the Django admin interface works great, except that the "View on site" link doesn't work. Whenever I try to use it, I get an OperationalError with the message: no such table: django_site. I've done some research into this problem, and it seems that I have to set up the Django sites framework for this link to work, but I'm exactly sure how to do that. The documentation talks about database tables, etc., but it doesn't tell how to actually set up a site. So my question is really two-fold:

  1. How do I get the sites framework set up? Do I have to create the table myself (and enter the data myself), or is there something I have to enable so ./manage.py syncdb will automagically "detect" that I want the table set up?
  2. Will setting up the sites framework effect me when I'm developing locally (i.e., just running on localhost and not off my actual domain name)? Will I have to add something to settings.py like SITE_ID = 2 if DEBUG else 1, or will manage.py just detect that I'm working on the debug site and not do anything with the sites framework?

解决方案

Putting

'django.contrib.sites',

into your INSTALLED_APPS and a following

$ ./manage.py syncdb

may suffice.

When installed, edit the Site instance (e.g. through /admin interface) to reflect your local hostname (e.g. localhost:8000).

这篇关于如何获取Django管理员的“现场查看”链接到工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆