小编Xun*_*ang的帖子

django:在包含的模板中使用块

我有一些html结构,可以在很多不同的地方重用.它与整体模板不同,所以我不能扩展它,它也可以用来包含复杂的内容,所以我不认为将它定义为模板标签做得很好.下面是一些描述我想要的结果的伪代码,当使用template_level2.html时,您可以通过调用其中的块轻松地将内容放入reusable_pattern_template.如果我使用此代码,则您在template_level_2.html的"实际内容"中所写的内容将不会显示.我应该怎么处理这个?

base.html文件

<html>
<head></head>
<body>
{% block content %}{% endblock %}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

template_level1.html

{% extends 'base.html' %}
{% block content %}
  Something here...
  {% include 'reusable_pattern_template.html' %}
  Something else here...
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

reusable_pattern_template.html

<div>
  <div>
    <div>
      {% block local_content %}{% endblock %}
    </div>
   </div>
</div>
Run Code Online (Sandbox Code Playgroud)

template_level2.html

{% extends 'template_level1.html' %}
{% block local_content %}
  Actual content here...
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

更新: 对不起,template_level2.html中的扩展有一些拼写错误,我刚刚更正了.

它可能不是很清楚,但上面的代码更像是一个描述我想要的结果的伪代码.简而言之,

  • 我想在我的模板中包含一些可重复使用的html模式.
  • 这些模式就像盒子一样,你可以把整个html内容放在其中.因此,对于我的目的,上下文变量可能有点过于有限

django django-templates

37
推荐指数
3
解决办法
3万
查看次数

从派生类对象调用基类方法

如何从派生类对象中调用派生类重写的基类方法?

class Base{
  public:
    void foo(){cout<<"base";}
};

class Derived:public Base{
  public:
    void foo(){cout<<"derived";}
}

int main(){
  Derived bar;
  //call Base::foo() from bar here?
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

36
推荐指数
2
解决办法
7万
查看次数

纱线工作区、反应、monorepo 问题与冲突库版本

我正在试验纱线工作区 monorepo。它由一个用 创建的 TestProjectcreate-react-app和一个用创建的 SharedLib1 组成create-react-library。TestProject 从 SharedLib1 导入代码。问题是,TestProject 使用依赖于 babel-jest ^24.9.0 的 react-scripts 3.3.0,而 SharedLib1 使用依赖于 babel-jest 22.4.4 的 react-scripts-ts ^2.16.0。yarn start在 TestProject 中运行时,它抱怨:

The react-scripts package provided by Create React App requires a dependency:

  "babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:

  /monoRepo/node_modules/babel-jest (version: 22.4.4) 
Run Code Online (Sandbox Code Playgroud)

我可以通过SKIP_PREFLIGHT_CHECK=true在 TestProject 中设置或手动升级 SharedLib1 中的 react-scripts来禁用错误,但我想知道是否有更好的方法来处理这个问题。 …

reactjs create-react-app monorepo yarnpkg yarn-workspaces

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

什么是"django后端"?

我一直在遇到很多提到'后端'的django应用程序,但不知道它是什么.在谷歌周围搜索并没有给出关于django后端的一般结果.有人可以解释一下吗?

具体来说,请看这些例子:

实际上我认为前两个和第三个有点不同,我更不确定的是前两个:应用程序中包含的后端.

django backend

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

django model CharField:max_length不起作用?

我正在努力创造一个有限选择的领域:

Action_Types=(
              ('0','foo'),
              ('1','bar'),
              )

class Foo(models.Model):
    myAction=models.CharField(max_length=1,choices=Action_Types)

    def __unicode__(self):
        return '%d %s'%(self.pk,self.myAction)
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试插入违反规则的内容时,它成功了,没有任何错误或警告消息(使用"manage.py shell").似乎任何长度的任何文本都可以放入这个领域.我使用SQLite3作为后端.

这应该是那样的吗?或者如果我错过了什么?

sqlite django model choice maxlength

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

正则表达式:如何匹配包含"\n"(换行符)的字符串?

我正在尝试使用正则表达式从SQL导出文件中转储数据.为匹配帖子内容的字段,我使用' (?P<content>.*?)'.它在大多数情况下工作正常,但如果字段包含'\n'字符串,则正则表达式将不匹配.如何修改正则表达式以匹配它们?谢谢!

示例(我正在使用Python):

>>> re.findall("'(?P<content>.*?)'","'<p>something, something else</p>'")
['<p>something, something else</p>']

>>> re.findall("'(?P<content>.*?)'","'<p>something, \n something else</p>'")
[]
Run Code Online (Sandbox Code Playgroud)

PS看起来前面带有'\'的所有字符串都被视为转义字符.我怎么能告诉regx按原样对待他们?

python regex escaping line-breaks

10
推荐指数
1
解决办法
2万
查看次数

React - Jest - Enzyme:如何模拟 ref 属性

我正在为带有 ref 的组件编写测试。我想模拟 ref 元素并更改一些属性,但不知道如何操作。有什么建议?

// MyComp.jsx
class MyComp extends React.Component {
  constructor(props) {
    super(props);
    this.getRef = this.getRef.bind(this);
  }
  componentDidMount() {
    this.setState({elmHeight: this.elm.offsetHeight});
  }
  getRef(elm) {
    this.elm = elm;
  }
  render() {
    return <div>
      <span ref={getRef}>
        Stuff inside 
      </span>
    </div>
  }
}

// MyComp.test.jsx
const comp = mount(<MyComp />);
// Since it is not in browser, offsetHeight is 0
// mock ref offsetHeight to be 100 here... How to?
expect(comp.state('elmHeight')).toEqual(100);
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs enzyme

10
推荐指数
1
解决办法
2万
查看次数

从pip安装app的python运行测试

对于某些python应用程序,如果我手动安装它们,我可以python setup.py test在app文件夹中运行以执行测试脚本.但是如果我通过pip安装它们,dist-packages中只有一个.egg文件,那么我应该如何运行他们的测试?

python ubuntu pip

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

C++:条件继承是可能的

我正在研究微处理器(Arduino)项目.我的库Foo继承自现有的库Basic.后来我将其功能扩展Basic到了另一个类Advanced.然而,Advanced更难以延伸硬件,使已经制作的一个演示无法使用.

我在想的是如下:

class Foo:
#ifndef USE_BASIC
public Advanced
#else
public Basic
#endif
{
...
}
Run Code Online (Sandbox Code Playgroud)

#define USE_BASIC输入我的演示代码:

#define USE_BASIC
#include <Foo.h>
Run Code Online (Sandbox Code Playgroud)

但是,Foo不是继承自Basic.我在这做错了吗?或者,如果有其他方法可以解决这个问题?

c++ inheritance arduino

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

Arduino库:函数的多个定义

今天我在尝试使用IRremote库时遇到了一个奇怪的问题,我设法解决了以下问题.如果你在库中有一个文件夹,包含Foo.hFoo.cpp在里面,并写一个草图来包含Foo.h:

foo.h中

#ifndef Foo_H
#define Foo_H

int AAA() {
    return 0;
}

#endif
Run Code Online (Sandbox Code Playgroud)

Foo.cpp中

#include "Foo.h"
Run Code Online (Sandbox Code Playgroud)

草图

#include <Foo.h>

void setup(){

}

void loop(){

}
Run Code Online (Sandbox Code Playgroud)

错误消息是:

 Foo\Foo.cpp.o: In function `AAA()':

 E:\workShop\Arduino\libraries\Foo\/Foo.h:5: multiple definition of `AAA()'

 includeTest.cpp.o:E:\workShop\Arduino\libraries\Foo/Foo.h:5:

 first defined here
Run Code Online (Sandbox Code Playgroud)

我正在使用Windows 7 32位机器.在Arduino 1.0.5,1.0.4和21,22上测试.


因此,通过一些研究,我发现问题来自于我对预处理器和链接的混淆.这个问题解释了预处理器如何包含文件和包含防护:

以下是帮助我理解链接的一些页面:

这是对内联说明符的更好解释:

c++ arduino

7
推荐指数
2
解决办法
1万
查看次数