小编Sug*_*san的帖子

Django:在哪里存储所有应用程序通用的函数

我是 django 新手我有一些功能,项目中的所有应用程序都会使用这些功能,我不知道在哪里存储这些文件以及如何调用它们。

是否有推荐的方法将这些文件存储在项目中。

django

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

在jQuery中的结束标记之前添加HTML

我想在之间使用jQuery添加HTML

</font></td>

<table>
    <tr>
        <td>
            <span>something</span>
            <font color="#C40404">*</font>
        </td>
    <tr>
</table>
Run Code Online (Sandbox Code Playgroud)

jquery

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

Javascript:mutationobserver没有警报消息

我正在尝试检测元素中CSS属性的更改。我在网上搜索并找到了MutationObserverjavascript API。但是在我的测试脚本中,它无法按预期运行(它不会警告属性名称和属性值)。

var foo = document.getElementById("hideit");

var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    alert('mutation.type = ' + mutation.type);

  });

});
observer.observe(foo);
observer.disconnect();

$(function() {
  $("#clickhere").on("click", function() {
    $("#hideit").slideToggle('fase');
  });

});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<body>
  <div id="clickhere">click to toggel</div>
  <div id="hideit" style="display:none;">this is the content of the hide/show toggle</div>

</body>
Run Code Online (Sandbox Code Playgroud)

它显示了一个JavaScript错误

TypeError: Argument 1 of MutationObserver.observe is not an object.
Run Code Online (Sandbox Code Playgroud)

谢谢提前

javascript mutation-observers

2
推荐指数
2
解决办法
2784
查看次数

php oop visibility:父类中的函数如何调用它自己的私有函数和子类公共函数

我不知道如何提出这个问题,这就是为什么标题不是.如果有人可以,请改变它..

它位于方法可见性下的PHP文档http://php.net/manual/en/language.oop5.visibility.php中

<?php

class Bar 
{
    public function test() {
        $this->testPrivate();
        $this->testPublic();
    }

    public function testPublic() {
        echo "Bar::testPublic\n";
    }

    private function testPrivate() {
        echo "Bar::testPrivate\n";
    }
}

class Foo extends Bar 
{
    public function testPublic() {
        echo "Foo::testPublic\n";
    }

    private function testPrivate() {
        echo "Foo::testPrivate\n";
    }
}

$myFoo = new Foo();
$myFoo->test(); // Bar::testPrivate 
                // Foo::testPublic
?>
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,如何$myFoo->test()打印Bar::testPrivateFoo::testPublic 我认为它将打印Foo::testPrivateFoo::testPublic

php oop

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

django.core.exceptions.FieldError: Unknown field(s) (username) specified for Employee

I am trying to extend the user model

so I created a new model called employee with foreignkey to user model

from django.db import models

from django.contrib.auth.models import User

class Employee(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    department = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)

and tried to create a form for the signup

from django.contrib.auth.forms import UserCreationForm
from employee.models import Employee

class EmployeeForm(UserCreationForm):
    class Meta(UserCreationForm.Meta):
        model = Employee
        fields = UserCreationForm.Meta.fields + ('department',)
Run Code Online (Sandbox Code Playgroud)

These are the only changes I made I am getting the following error: …

python django

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

不同端口上的多个无服务器进程

我有多个无服务器应用程序我使用无服务器离线插件在本地运行它

我正在设置端口

custom:
  serverless-offline:
    httpPort: 4000
Run Code Online (Sandbox Code Playgroud)

另一个无服务器

custom:
  serverless-offline:
    httpPort: 3000
Run Code Online (Sandbox Code Playgroud)

在任何时候,我只能运行其他节目的一项服务:

在端口 3002 上启动无服务器离线 lambda 服务器时出现意外错误:{ 错误:侦听 EADDRINUSE:地址已在使用中

但我没有在任何地方使用 3002 但它显示 3002

这是什么错误?

127.0.0.1:3002

serverless

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

imagepng:如何将输出保存在变量中,然后使用img标签显示它

我想将imagepng的输出保存到变量而不是显示它,然后想在img标签中使用变量来显示图像.我该怎么做?

我正在使用一个聪明的模板,我需要将结果图像保存到variabe,然后将其显示在一个智能模板tpl文件中

谢谢它提前

php

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

django:信号不工作 pre_save()

我有用户应用程序。

在 signal.py 我有

from django.db.models.signals import pre_save
from user.models import User
from django.dispatch import receiver
import random
import string

@receiver(pre_save,sender=User)
def create_hash_for_user(sender,instance,**kwargs):
    allowed_chars = ''.join((string.ascii_letters, string.digits))
    unique_id = ''.join(random.choice(allowed_chars) for _ in range(32))
    print("Request finished!")
    instance.user_hash = unique_id
    instance.save()
Run Code Online (Sandbox Code Playgroud)

在apps.py中

from django.apps import AppConfig


class UserConfig(AppConfig):
    name = 'user'

    def ready(self):
        import user.signals
Run Code Online (Sandbox Code Playgroud)

在 models.py 中,我扩展了abstractbaseuser

from django.db import models
from django.shortcuts import render
from django.core.exceptions import ValidationError
from django.contrib.auth.models import (
        AbstractBaseUser,
        BaseUserManager
    )

from .utils import file_size …
Run Code Online (Sandbox Code Playgroud)

python django

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

我的 smarty 模板未显示

我在 Linux 上使用 Php Smarty。

我的 PHP 文件中有一行:

$phpsmart->display("pagetemplate.tpl");
Run Code Online (Sandbox Code Playgroud)

该行应该显示pagetemplate.tpl. 事实并非如此。

php smarty

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