简体   繁体   English

将Python打印语句转换为Django

[英]Translating Python print statements to Django

I am in the process of creating a Django web application that reads a URL and outputs selected data from the page. 我正在创建一个Django Web应用程序,该应用程序读取URL并从页面输出选定的数据。 I have written the code in Python that parses the web page and it currently returns the information that I need to display in the Django app as desired. 我已经用Python编写了用于解析网页的代码,并且该代码当前返回了我需要显示在Django应用中的信息。

Before I dive in I just want to confirm what I have researched is correct as I only have a limited time to complete the project. 在我潜水之前,我只想确认我研究的内容是正确的,因为我只有有限的时间来完成该项目。

To summarise my python code, it is in the src folder in a class called "manage.py" 总结一下我的python代码,它位于src文件夹中的“ manage.py”类中

I have created print statements that print the information that I need to display (I did this to ensure it was returning the correct data) 我创建了打印语句,用于打印需要显示的信息(这样做是为了确保它返回了正确的数据)

print(variable1)

print("some text" + variable2)

Can I create the Django app code in the same file, "manage.py"? 我可以在同一文件“ manage.py”中创建Django应用代码吗? (The project has already been created as a Django app in Eclipse when I started building the project) (当我开始构建项目时,该项目已经在Eclipse中创建为Django应用)

Would I build the Django code as I've estimated below if I'm using the variables defined from the Python code above? 如果我使用上面的Python代码定义的变量,是否可以按照下面的估计来构建Django代码?

<!DOCTYPE>
<html>
<head>
    <title>{% block title %}Title of website{% endblock %}</title>
</head>

<body>
    <h1>Web page report</h1>

    <h2>Summary of web page</h2>

    <h3>Title of document</h3>
    <p>{{variable1}}</p>

    <h3>The file size of the document</h3>
    <p>{"Some text" + {variable2}}</p>  
</body>
</html>

Django has strict rules about where to place which information. Django对于在哪里放置哪些信息有严格的规定。 You can not write everything into manage.py. 您不能将所有内容都写入manage.py。 Answering requests from the browser is for example done using view functions. 例如,使用视图功能来完成来自浏览器的应答请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM