【问题标题】:a href cannot transfer me to html page?href 不能将我转移到 html 页面?
【发布时间】:2021-10-07 08:26:56
【问题描述】:

我在这里尝试创建 cv 站点,除了图像它没有出现,当我运行项目并与我联系时,它应该将我转移到 contact.html 页面,但它不起作用,请我遵循一些课程并确定每件事都一样,但我不知道问题出在哪里

谢谢你

civi.py:

from flask import Flask, render_template
from flask.helpers import url_for


project=Flask(__name__)
@project.route("/")

def enterance():
    return render_template("enterance.html")


project.run()

模板/Hajar.png

模板/enterance.html:

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>HajarBaabbad</title>
</head>
<body>
    <table cellspacing="20">
        <td>
            <img src="Hajar.png" alt="Hajar Logo">
        </td>
        <td>

            <h2>My Hobbies</h2>
            <ul>
                <li>reading book</li>
                <li>swemming</li>
            </ul>
            <hr>

        </td>
    </table>
    <h1>Hajar Abdullah Ba'abbad</h1>
    <p>python developer</p>
    <p>personal linkedin page: <a href="https://www.linkedin.com/in/hajar-baabbad-7714951a0/">My linkedin pg</a> </p>
    <hr>
    <h2>My Experience</h2>
    <ol>
        <li>Computer Teacher</li>
        <p><strong>August 2018 - August 2019
              </strong>
             <p><em>Success International School Riyadh</em></p>
           
             May 2014 - August 2019
        
            Set in classes of fellow teaching professionals to learn innovative methods for
            dispensing information to students.
            •
            Established positive rapport with all students and parents through home
            calls, emails and Parent Teacher Club.
            •
            • Assisted children per station during small-group learning periods.
            Prepared instruction materials including copying, construction of bulletin
            boards, grading work and setting up work areas.
            •
            • Administered and graded tests and assignments to evaluate students' progress.
            • Planned and supervised class projects, field trips and visits by guest speakers.
            Leveraged diverse learning strategies to prepare students for higher-level
            education requirements.
            </p>
        <li>
            Executive Secretary
            <p><strong>Success International School, Riyadh</strong></p>
            <p>May 2014 - August 2019</p>
            <p>
                Answered and managed incoming and outgoing calls while recording
                accurate messages for distribution to office staff.
        
                Greeted incoming visitors and customers professionally and provided
                friendly, knowledgeable assistance.
                
                Managed paper and electronic filing systems by routing various documents,
                taking messages and managing incoming and outgoing mail.
                
                Composed internal memos and external correspondence for senior
                management and reviewed all documentation to eliminate errors.
                
                Identified and recommended changes to existing processes to improve
                accuracy, efficiency and responsiveness of customer service department.
            </p>
        </li>
    </ol>
    <hr>
    
    <h2>Education</h2>
    <ol>
        <li>Bachelor of Administrative Science</li>
        <li>Diploma of Programming & Databases</li>
    </ol>

    <hr>
    <h2>Certificates:</h2>
    <ul>
        <li> Certified Entry-Level Python Programmer( PCEP) OpenEDG Python institute- 2021</li>
    <li> Fundamentalsof Python programming - 2020
    </li>
    <li> Projects in Django: Learn Djangobuilding project - 2020
    </li>
        <li> Certificate in IT SkillsCIT - 2020
        </li>
        <li>
             Complete motivation power - 2012

        </li>
        <li>
             Goals Creation - 2016

        </li>

</ul>

    <hr width="10">
<hr>

<h2>My Skills</h2>
<table cell>
    <tr>
    <th>Python</th>
    <td>❤????</td>
    <th>Java</th>
    <td>????????</td>
    </tr>
    <tr>
        <th>reading</th>
        <td>????</td>
        <th>writing</th>
        <td>✔</td>
    </tr>
</table>

<a href="contact.html" >contact me</a>
</body>
    
</html>

模板/contact.html:

<!DOCTYPE html>
<head>
    <meta charset="ut-8">
    <title>Contact Info</title>
</head>
<body>
    <h3>My Contact information :</h3>
    <p>KSU, Riyadh (Olaya)</p>
    <p>tel:05847213</p>
    <p>po:12345</p>
    <p>my email:hajar@gmail.com</p>
    <form action="mailto:Almuttahida@gmail.com" method="post" enctype="text/plain">
        <label><strong>your name:</label></strong><br>
        <input type="text" name="your name" value=""><br>
        <label><strong>your email</strong></label><br>
        <input type="email" name="your email" value=""><br>
        <label><strong>your message:</strong></label><br>       
        <textarea name="message" rows="10" cols="10"></textarea><br>
        <input type="submit" name="">
    </form>
</body>
</html>

我的项目包含 scrp 文件夹,因为 venv 我激活了它的脚本、模板包和 civi.py 在下面我将通过 scrp 树和模板树

模板树:

????templates
 ┣ ????contact.html
 ┣ ????enterance.html
 ┗ ????Hajar.png

scrp 树:(我删除了大部分代码,因为它比这里可用的时间长)

????scp
 ┣ ????Include
 ┣ ????Lib
 ┃ ┗ ????site-packages
 ┃ ┃ ┣ ????click
 ┃ ┃ ┃ ┣ ????__pycache__
 ┃ ┃ ┃ ┃ ┣ ????core.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????decorators.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????exceptions.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????formatting.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????globals.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????parser.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????shell_completion.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????termui.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????testing.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????types.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????utils.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????_compat.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????_termui_impl.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????_textwrap.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????_unicodefun.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┣ ????_winconsole.cpython-38.pyc
 ┃ ┃ ┃ ┃ ┗ ????__init__.cpython-38.pyc
 ┃ ┃ ┃ ┣ ????core.py
 ┃ ┃ ┃ ┣ ????decorators.py
 ┃ ┃ ┃ ┣ ????exceptions.py
 ┃ ┃ ┃ ┣ ????formatting.py
 ┃ ┃ ┃ ┣ ????globals.py
 ┃ ┃ ┃ ┣ ????parser.py
 ┃ ┃ ┃ ┣ ????py.typed
 ┃ ┃ ┃ ┣ ????shell_completion.py
 ┃ ┃ ┃ ┣ ????termui.py
 ┃ ┃ ┃ ┣ ????testing.py
 ┃ ┃ ┃ ┣ ????types.py
 ┃ ┃ ┃ ┣ ????utils.py
 ┃ ┃ ┃ ┣ ????_compat.py
 ┃ ┃ ┃ ┣ ????_termui_impl.py
 ┃ ┃ ┃ ┣ ????_textwrap.py
 ┃ ┃ ┃ ┣ ????_unicodefun.py
 ┃ ┃ ┃ ┣ ????_winconsole.py
 ┃ ┃ ┃ ┗ ????__init__.py

【问题讨论】:

  • 可能是因为contact.html和Hajar.png在“templates”路径下,但是你的路由是“/”

标签: python html href


【解决方案1】:

欢迎来到 SO,

我发现您的代码中的相对 URL 不正确。

以下是一些使用相对路径的示例:

参考相对路径,可以参考当前工作目录,语法如下:./image.png

要移动到子文件夹,只需键入:./subfolder/image.png

如果您在子文件夹中工作并且想要引用父文件夹,您可以写:../

../../ 向后移动两个目录(等等...)

在您的具体情况下,只需编辑如下:

<img src="./Hajar.png" alt="Hajar Logo">

<a href="./contact.html" >contact me</a>

移动到联系页面的另一种方法是创建一个新的路由函数,如下所示:

@project.route("/contact")
def contact():
    return redirect(url_for('contact'))

然后在锚标签中调用它:

<a href="/contact" >contact me</a>

它应该可以工作,如果不是,我恳请您评论或编辑问题并清楚地显示您项目的文件夹树。

【讨论】:

  • 对不起,你能告诉我怎么做吗?我写了这一切,1个.py文件和模板包内带有2个html文件的图像.. :(
  • @Sara 你能告诉我你当前的文件夹树吗?这里是一个文件夹树的例子:link
  • @Sara 我根据您在问题中添加的内容更改了我的答案。让我知道它现在是否有效
  • 我真的被困在这里它不起作用我改变了你说的 url 没有任何响应同样的问题:|
  • 实际上,当我在 V.S 中运行 enterance.html 时,一切正常,但是当我在 cmd 中运行代码并复制过去的 url 时,除了 image 和 contact.html 传输之外,enterance.html 工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-27
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 2019-01-12
相关资源
最近更新 更多