如何在Python中使用Django使html/css框架更快?

2024-09-20 23:07:48 发布

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

我已经单独为html和css做了非常繁琐的任务来制作pH气压计,但是我发现pythondjango有一个函数可以在几秒钟内完成这项工作。你是怎么做到的?你知道吗

<!DOCTYPE html>
<html>
    <head>
        <title>Color</title>
        <style type="text/css">
            body {
                background-color: silver;
                color: white;
                padding: 20px;
                font-family: Arial, Verdana, sans-serif;}
            h1 {
                background-color: #fffffff;
                background-color: hsla(0,100%,100%,0.5);
                color: #64645A;
                padding: inherit;}
            p {
                padding: 5px;
                margin: 0px;}
            p.zero{
                background-color: rgb(238,62,128);}
            p.one {
                background-color: rgb(244,90,139);}
            p.two {
                background-color: rgb(243,106,152);}
            p.three {
                background-color: rgb(244,123,166);}
            p.four {
                background-color: rgb(245,140,178);}
            p.five {
                background-color: rgb(245,159,192);}
            p.six {
                background-color: rgb(245,176,204);}
            p.seven {
                background-color: rgb(0,187,136);}
            p.eight {
                background-color: rgb(140,202,242);}
            p.nine {
                background-color: rgb(114,193,240);}
            p.ten {
                background-color: rgb(84,182,237);}
            p.eleven {
                background-color: rgb(48,170,233);}
            p.thirteen {
                background-color: rgb(0,160,230);}
            p.fourteen {
                background-color: rgb(0,136,221);}
        </style>
    </head>
    <body>
        <h1>pH Scale</h1>
        <p class="fourteen">14.0 VERY ALKALINE</p>

从这个来源What is the difference between Django and Html?

我必须在Django中找到什么函数或设置才能在几秒钟内生成任何html/css框架,因为单独使用html和css来生成这样的框架是非常繁琐的任务?你知道吗


Tags: 函数titlestylehtmlbodyrgbh1css
2条回答

你有很多解决方案。例如,在您的例子中,您可以创建一个模板标记来在您的应用程序中生成CSS基本.html使用for生成CSS的模板。你知道吗

看看这个例子如何创建一个简单的标记:https://docs.djangoproject.com/en/2.1/howto/custom-template-tags/#simple-tags

问题是,您没有在答案上添加详细信息,而是获取数据以创建RGB值。如果RGB与在模板中渲染的模型相关,则可以使用inline style CSS

最后一个解决方案可以使用模板标记完成,该模板标记可以基于对象中的数据以CSS样式呈现对象。你知道吗

@register.inclusion_tag('element.html')
def render_element(element *args, **kwargs):

    context = {}
    # here based on your element you can decide what to add 
    # in the context. You can also create `inline css` that your
    # template will render as you want.
    ...
    return context

请参见此处的详细信息:https://docs.djangoproject.com/en/2.1/howto/custom-template-tags/#inclusion-tags

你的问题是严格的渲染问题,所以我会避免涉及模型。你知道吗

嗯,我不知道有哪一个函数可以使pH晴雨表的颜色,但如果你正在寻找某种框架,使CSS样式更快,也许你想先看看引导。它是一个快速的插件,可以让你的应用程序看起来很快,它附带了很多特殊的CSS样式,你可以实现得更快。你知道吗

https://www.w3schools.com/bootstrap/bootstrap_get_started.asp

另外,您可能需要考虑为您的CSS制作一个单独的样式表。你知道吗

https://docs.djangoproject.com/en/2.1/intro/tutorial06/

相关问题 更多 >

    热门问题