小编Roo*_* DJ的帖子

Django 将变量传递给模板

嗨,谢谢你的帮助,我编码很差。

指出:我正在做一个 Django 项目,将数据表单数据库传递给前端;但现在我什至无法将 Django 的任何视图传递到模板中,我怀疑我传递了错误的变量类型;请对您的想法发表评论。

这是我在views.py上的代码:

from django.shortcuts import render

def index (requset):
    return render(requset,'myapp/index.html') # link to be able open frountend

def testdex(requset):
    text = "hello world"
    context ={'mytext' : text }
    return render(requset,'myapp/inculdes.html', context)
Run Code Online (Sandbox Code Playgroud)

所以我的变量将被传递到扩展到索引页的 inculdes

这是我在 inculdes.html 中的代码:

{% exntends "myapp/index.html" %}

{% block includes %}
{{ mytext }}
{% endblock includes %}
Run Code Online (Sandbox Code Playgroud)

这是我在 index.html 上的代码:

<body>
{% block includes %} {% endblock includes %}    
</body>
Run Code Online (Sandbox Code Playgroud)

再次感谢您给我时间来帮助我,如果可以给我写一些代码,我将不胜感激,因为尝试整周解决这个问题

html django django-templates django-views

12
推荐指数
2
解决办法
3万
查看次数

无法 pip install mysqlclient 并执行“gcc”:权限被拒绝

如果我问一些非常简单的事情,请原谅我

我正在远程服务器上设置一个 Django 应用程序,通过 Namecheap(无根访问权限)

和我的服务器信息:

Apache 版本:2.4.38

MySQL 版本:10.1.38-MariaDB-cll-lve

架构:x86_64

操作系统:linux

蟒蛇:3.7

姜戈:2.1.7

现在我正在尝试将 mysql DB 连接到我的 django 应用程序。

但是当我尝试安装连接器mysqlclientpip install mysqlclient

我有这个错误:

  $ pip install mysqlclient
  Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command /home/letsilap/virtualenv/IOT/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_19o3wdf/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmp45bylejwpip-wheel- --python-tag cp37:
  /opt/alt/python37/lib64/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  running bdist_wheel
  running build …
Run Code Online (Sandbox Code Playgroud)

python mysql pip

5
推荐指数
1
解决办法
2967
查看次数

标签 统计

django ×1

django-templates ×1

django-views ×1

html ×1

mysql ×1

pip ×1

python ×1