标签: include

在 Django 中,{{ block.super }} 出现问题,如何避免在多个模板文件中复制“块”?

对于继承块的 2 个子模板文件,{{ block.super }}未解析

Python 2.5.2、Django 1.0、Windows XP SP3

所涉及文件的示例框架代码:

  1. base.html
  2. item_base.html
  3. show_info_for_all_items.html
  4. show_info_for_single_item.html

文件 : base.html

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

文件 : item_base.html

{% extends "base.html" %}
{% block item_info %}   
    Item : {{ item.name }}<br/>
    Price : {{ item.price }}<br/>   
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

文件 : show_info_for_all_items.html

{% extends "item_base.html" %}
{% block content %}
    <h1>info on all items</h1>
    <hr/>
    {% for item in items %}
        {% block item_info %}
            {{ block.super }} …
Run Code Online (Sandbox Code Playgroud)

django include django-templates

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

PHP 包含不工作

该站点应如下所示。但是我使用 PHP 包含(就像我在另一个站点上那样)插入页眉和页脚(所以当我想对其中一个页面进行更改时,我不必更改每个页面)。

现在,这就是它向我展示的。它只是出于某种原因没有阅读 PHP。文件名是对的。我试图调用该页面大约有四个不同的文件。

感谢您的任何见解!

度母

html php include

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

为什么包含会阻止加载 php 页面?

我有我的 index.php 页面,只是在我的标题之后我想要include一个 message.php 文件。这个 message.php 文件执行一些 mysql 查询,运行几个函数,最后echo生成一些文本。

如果我访问 mysite.com/message.php - 我可以在浏览器中看到我需要的所有文本。但是,如果我添加以下行:

<?php include "message.php"; ?>
Run Code Online (Sandbox Code Playgroud)

到我的 index.php,页面只加载到include语句,然后产生 500 内部服务器错误。这怎么可能呢?我完全被困在这里...

编辑:我已经想通了,感谢您使用 apache 日志为我指出正确的方向。即使我没有日志访问权限,我也使用 statement 对 .htaccess 进行了编辑php_value error_log log.txt。它将错误转储到同一目录中的 txt 文件中。该错误是由一个名称已被使用的函数产生的。这就是为什么单独的环境不会产生错误的原因。

php include

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

包含在包含的文件中不适用于相对路径

在过去的 64 分钟里,这个错误耗尽了我的理性思考能力,我真的不知道我该怎么办。

当我在包含的文件中使用以下 3 行时:

var_dump(file_exists('G:/xampp/htdocs/myproject/public_html/includes/htmlPurifierAndMarkdown.php')); //retuurns true
var_dump(__FILE__);
include '../htmlPurifierAndMarkdown.php'; //gives error
Run Code Online (Sandbox Code Playgroud)

我得到以下输出:

boolean true

string 'G:\xampp\htdocs\myproject\public_html\includes\classes\genral.class.php' (length=71)


( ! ) Warning: include(../htmlPurifierAndMarkdown.php) [function.include]: failed to open stream: No such file or directory in G:\xampp\htdocs\myproject\public_html\includes\classes\genral.class.php on line 4
Call Stack
#   Time    Memory  Function    Location
1   0.0005  345328  {main}( )   ..\add.php:0
2   0.0036  382408  include( 'G:\xampp\htdocs\myproject\public_html\includes\classes\events.class.php' )    ..\add.php:28
3   0.0041  398024  include( 'G:\xampp\htdocs\myproject\public_html\includes\classes\standardpost.class.php' )  ..\events.class.php:2
4   0.0047  413928  include( 'G:\xampp\htdocs\myproject\public_html\includes\classes\genral.class.php' )    ..\standardpost.class.php:2
Run Code Online (Sandbox Code Playgroud)

简而言之:

  1. 第一行说明该文件不是我想象的一部分,它确实存在。
  2. 第二行告诉我的调用脚本的位置,仔细检查路径,你会注意到我试图包含的文件驻留在父目录中
  3. 包含函数表示文件不存在

所以我只是在想象东西还是这是一些严重的 php …

php path include

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

我应该使用哪个头文件而不是#include <bits/stdc ++.h>

#include <iostream>
#include <string>
#include <sstream>
//#include <bits/stdc++.h>
#include <iomanip>      // std::setprecision
#include <math.h> 
using namespace std;
Run Code Online (Sandbox Code Playgroud)

我想删除标题#include <bits/stdc++.h>,因为它显着减慢了我的编译时间.

当我删除它时,我收到以下错误:

error: cannot convert ‘long double*’ to ‘double*’ for argument ‘2’ to ‘double modf(double, double*)’
       fractpart = modf(val, &intpart);
Run Code Online (Sandbox Code Playgroud)

我认为问题是缺少头文件,但不知道它是哪一个.

我得到错误的代码是:

fractpart = modf(val, &intpart);
if (fractpart != 0) {
    throw Error("ERR");
}
Run Code Online (Sandbox Code Playgroud)

c++ type-conversion include header-files

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

动态地将布局包含到片段内的另一个布局文件中

我有一个片段布局,我想动态添加另一个子布局,

我试过这个/sf/answers/1581458861/

子布局xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:hint="Question"
    android:textColor="@color/colorTextBlack"
    android:textSize="16dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的主要布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f2f2"
android:orientation="vertical">
<FrameLayout
    android:id="@+id/flContainer"
    android:layout_width="match_parent"
    android:layout_margin="20dp"
    android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在我的片段中我包含了子布局

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_start_question, container, false);
     flContainer = (FrameLayout) v.findViewById(R.id.flContainer);
     flContainer.addView(R.layout.sub_layout);
    return v;
}
Run Code Online (Sandbox Code Playgroud)

但我在addView附近收到错误截图如下 在此输入图像描述

任何人都可以帮助找到错误

android include fragment android-layout android-fragments

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

如果一个类调用另一个类,我可以将它们放在单独的JAR文件中吗?

假设我有两个班机场和飞机:

public class Airport
{
    public static void main(String args[])
    {
        Airplane a1 = new Airplane();
    }
}

public class Airplane
{
    int seats;
    public Airplane()
    {
        seats = 10;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将这些类放在单独的JAR文件中,以便将来可以相互独立地开发它们,以防出现任何问题.由于Airport调用Airplane我必须AirplaneAirport源文件中导入.我想在项目中导入它们,我将用它来调用这些类.但即使我在项目中导入它们,仍然存在解决问题.

更新:你能举一个例子.classpath来完成这个调用层次结构吗?我只是将JAR添加到主项目的.classpath中,但Airport抱怨它无法找到方法Airplane.

呼叫树我想要完成的事情

java import jar include

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

包含<sstream>时是否自动包含<string>

这个问题显然是例如代码.很多时候,在展示std::stringstream示例时,我认为我需要明确添加#include <string>.

c++ string include

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

VSCode运行C ++代码时没有这样的文件或目录

当我尝试跑步时 我的代码 我收到此错误:

main.cpp:1:18:致命错误:temp.h:没有此类文件或目录#include“ temp.h”编译终止。

但是,Intellisense会检测到此标头存在。
Ctrl +左键单击main.cpp中的#include“ temp.h”成功将我带到该文件,并且该代码行在其下面没有任何弯曲的行。

我为.cpp文件和头文件有两个单独的文件夹,并在c_cpp_properties.json中配置了includePath,如下所示: c_cpp_properties屏幕截图

我的工作区文件夹是temp,“ $ {workspaceFolder} / **”行应递归地检查子文件夹中的标题。我将绝对路径添加到头文件没有成功。

c++ intellisense file include visual-studio-code

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

项目中多个包含相同的头文件:C vs C ++

在这里,我有一个示例项目,其中包含两个源文件和一个头文件,如下所示:

main.c:

#include<stdio.h>                                                               
#include "personal.h"                                                           
int main(){                                                                     
    i = 5;                                                                        
    printf("Value is %d\n",i);                                                    
    return 0;                                                                     
 }
Run Code Online (Sandbox Code Playgroud)

sub.c:

#include "personal.h"                                                           
// do nothing
Run Code Online (Sandbox Code Playgroud)

最后是personal.h:

#pragma once                                                                    
int i; 
Run Code Online (Sandbox Code Playgroud)

每个.c文件都包含personal.h,后者受“保护”。我用gcc编译,一切正常:

>gcc sub.c main.c -o out
>./out 
Value is 5
Run Code Online (Sandbox Code Playgroud)

但是对于g ++,会发生这种情况:

>g++ sub.c main.c -o out
/tmp/cctYwVnO.o:(.bss+0x0): multiple definition of `i'
/tmp/ccPElZ27.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

在文件链接方式,预处理器活动等方面,C ++和C之间在本质上有什么不同吗?我对其他编译器(如clang)尝试了相同的操作,并且发生了相同的情况。我也许在这里想念一些愚蠢的东西。

c c++ preprocessor compilation include

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