python - 部署了 rest-framework 的 django 时出错

标签 python django django-rest-framework

我在尝试打开 Django Rest 框架的 url 时遇到错误。 它在本地运行良好,但是当我将它部署到服务器时,出现以下错误。在服务器上我有 django 1.9。

Exception Value:    

'url' is not a valid tag or filter in tag library 'future'

Exception Location:     /home/maxo/django-trunk/django/template/base.py in parse, line 506

Error during template rendering

In template /usr/local/lib/python2.7/dist-packages/rest_framework/templates/rest_framework/base.html, error at line 1

'url' is not a valid tag or filter in tag library 'future'
1   

      {% load url from future %}



2   {% load staticfiles %}
3   {% load rest_framework %}
4   <!DOCTYPE html>
5   <html>
6       <head>
7           {% block head %}
8   
9               {% block meta %}
10                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
11                  <meta name="robots" content="NONE,NOARCHIVE" />

注意:当我删除以下行时: {% load url from future %} from base.html 它现在工作正常,但是 rest api 的风格消失了。有没有其他替代方法来替换 {% load url from future %}?

最佳答案

在 Django 1.9 中,url 模板标签已从 future 模板标签库中移除。

来自 Django 1.9 release notes :

ssi and url template tags will be removed from the future template tag library (used during the 1.3/1.4 deprecation period).

因此,现在您无法从 Django 1.9 中的 future 库加载 url 标记。您可以改用内置的 url 标记。

{% url 'some-url-name' %}

关于python - 部署了 rest-framework 的 django 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31624606/

相关文章:

python - pdb 不能中断另一个线程?

python - Django Nose 给出 "ImportError: cannot import name setup"?

Django REST Framework 创建嵌套序列化程序会出现 pk 错误

Django rest-auth注册。使用 token 认证时如何通过 key 返回user_id

python - 我将如何覆盖 django rest 框架中的 perform_destroy 方法?

python - 获取发送到/从某个号码发送的消息总数 - Twilio Python API

python - 使用 BeautifulSoup 在 Python 中抓取列表

python - 我可以将 cookie 从 python 导出到 Chrome 吗?

Django ModelForms __init__ kwargs 创建和更新

django - 如何在不重复太多的情况下处理 django DRF 中的时区?