如何将任何Django应用程序实施到我的项目中?

2024-04-26 13:31:05 发布

您现在位置:Python中文网/ 问答频道 /正文

有关如何实现django应用程序的示例的一般建议所需的帮助。你知道吗

我正在尝试实现一个名为django simple polls的django应用程序。你知道吗

安装应用程序后。。。你知道吗

pip install ...

…正在将应用程序添加到已安装的应用程序中

…服务器仍在运行。。。你知道吗

…迁移运行没有问题。。。你知道吗

…能够从管理员创建基本投票。。。你知道吗

问题从这里开始,因为我不知道如何在服务器上查看投票:

(一)

urlpatterns = [ ... url(r'^poll/', include('poll.urls')), ]

我猜投票应用程序安装在django的某个地方,所以我不必在我的项目中创建任何额外的文件夹/文件。使用include()函数需要导入库吗?这也意味着我只需要在那个特定的网址上进行投票?这意味着轮询.url'已经存在?你知道吗

(二)

在模板文件中添加此标记以显示投票:

{% load poll_tags %} ... {% poll %}`

同样,我的猜测只是创建任何模板文件夹,并把上面的代码作为基础。“…”是什么意思?。我应该把上面的代码放在哪里?我怎么称呼那个HTML文件?你知道吗

这几乎是将应用程序构建到项目中的唯一方法吗?你知道吗

谢谢

另外,在访问http://127.0.0.1:8000/poll的时候

^poll/

^admin/

^news/index/ [name='index']

^news/post/ [name='view_post']

^news/view/category [name='view_category']

The current path, poll, didn't match any of these.

但有一条路叫做投票。:)

遵循指导:https://github.com/applecat/django-simple-poll/blob/master/README.md

我创建了以下基本模板:

<!DOCTYPE html>
<html>
    <head>
        <title>Polls</title>

        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    </head>

    <body>

        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

        {% load poll_tags %}
        ...
        {% poll %}
    </body>
</html>

我无法将在管理中创建的调查呈现到网站上。你知道吗


Tags: 文件djangonamehttpscomview模板应用程序
1条回答
网友
1楼 · 发布于 2024-04-26 13:31:05

questions starts here as I do not know how can I see the poll on the server

答:请确保更改投票的URL映射网址.py. 你知道吗

urlpatterns = [ ... url(r'^poll/', include('poll.urls')), ]

这应该添加到项目的网址.py你知道吗

Again my guess is just to create any template folder and put as base the code above. What does "..." mean?. Where do I put the above code? How do I call that HTML file?

如果您已将模板文件夹设置为设置.py您可以创建另一个名为poll的文件夹,然后将模板放在那里。那么就你的观点来说。你知道吗

from django.shortcuts import render

def index(request):
    return render(request, 'poll/yourtemplatename.html')

相关问题 更多 >