小编Ale*_*chi的帖子

数据库(database/database.sqlite)不存在.数据库来自工匠修补匠

我在文件database夹中创建了我的database.sqlite文件.我的.env文件内容是:

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=absolute\path\to\database\database.sqlite
DB_USERNAME=admin
DB_PASSWORD=
Run Code Online (Sandbox Code Playgroud)

当我运行时php artisan tinker,DB::table('users')->get();我从数据库中获取信息.

我的DatabaseController是:

class DatabaseController extends Controller
{
    public function main()
    {
        $users = DB::table('users')->get();

        return view('database',compact($users));
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,当我请求/database路径时,我收到错误:

QueryException in Connection.php line 647: Database (database/database.sqlite) does not exist. (SQL: select * from "users")

更新:临时修复是从config文件夹更改database.php :

  'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => 'absolute\path\database\database.sqlite', 
        'prefix' => '',
    ],
Run Code Online (Sandbox Code Playgroud)

而不是使用env('DB_DATABASE', database_path('database.sqlite')),而database/database.sqlite不是我的绝对路径.

database sqlite connection configuration laravel

14
推荐指数
6
解决办法
1万
查看次数

无法应用属性类“JsonConverter”,因为它是抽象的

我正在使用 Newtonsoft JSON 库,并且正在尝试反序列化 JSON。问题是,当我使用时,[JsonConverter(typeof(StringEnumConverter))]我收到此错误:Cannot apply attribute class 'JsonConverter' because it is abstract.

这是我的课程:

 public class ActionRepository
{
    [JsonConverter(typeof(StringEnumConverter))]
    public enum AllowedActions
    {
        FINDWINDOW,
    }

    public enum AllowedParameters
    {
        WINDOWNAME,
    }
}



public class Action
{
    public AllowedActions Name { get; set; }
    public List<Parameter> Parameters { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我在JsonConverter.

编辑:如果我导航到该类(在 VS 中按 Ctrl+单击),则 JsonConverter 类确实是抽象的。我使用 .NET for Windows Universal。

c# json json.net

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

Python PILLOW库使用CPU进行图像处理,可以在GPU上完成吗?

我为自己制作了一个小型的Python 3.x应用程序,它按照给定的百分比调整文件夹中的所有图像.

该应用程序支持多核CPU,因为它分割了与CPU一样多的线程完成的工作.

这里的瓶颈是CPU,因为我的RAM内存保持40%可用,运行时我的硬盘使用率为3%,但所有CPU内核都接近100%.

有没有办法在GPU上处理图像?我认为它会大大提高性能,因为GPU有超过4个核心.

以下是关于如何完成处理的一些代码:

def worker1(file_list, percentage, thread_no):
    """thread class"""
    global counter
    save_dir = askdir_entry.get() + '/ResizeImage/'
    for picture in file_list:
        image = Image.open(picture, mode='r')
        image_copy = image.copy()
        (width, height) = image.size
        filename = os.path.split(picture)[1]
        image_copy.thumbnail((width * (int(percentage) / 100), height * (int(percentage) / 100)))
        info_area.insert('end', '\n' + filename)
        info_area.see(tkinter.END)
        image_copy.save(save_dir + filename)
        counter += 1
        if counter % 3 == 0:
            update_counter(1, thread_no)
    update_counter(0, thread_no)


def resize():
    global start_time
    start_time = timeit.default_timer()
    percentage = percentage_textbox.get()
    if not …
Run Code Online (Sandbox Code Playgroud)

python tkinter image-processing pillow

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

Python 3 ConfigParser 也读取内联注释

我有以下代码,其中filePath是磁盘上 cfg 文件的路径。当我解析它时,它还会读取内联注释(带有空格 + 的注释";")。

结果的一些行:

xlsx:是的;评论在这里

html:是的;评论在这里

它应该是:

xlsx:是的

html:是的

def ParseFile(filePath):
    """this function returns the parsed CFG file"""
    parser = configparser.ConfigParser()
    print("Reading config file from %s" % filePath)
    parser.read(filePath)
    for section in parser.sections():
        print("[ SECTION: %s ]" % section)
        for option in parser.options(section):
            print("%s:%s" % (option, parser.get(section, option)))
Run Code Online (Sandbox Code Playgroud)

parsing config configparser python-3.x

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

按与 Laravel 和 Eloquent 的关系计数和排序

如何使用洋洋洒洒数的数量commentspost和秩序posts的数量comments

我的代码是这样的:

class Post extends Model
{
    protected $table = 'posts';

    public function comments()
    {
        return $this->hasMany('App\Comment');
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要以优雅的方式检索按评论数量排序的帖子集合,因此我不想使用类似的东西DB::select(select count(comment.post_id), post.id from posts left join comments on posts.id = comments.post_id group by post.id order by count(post.id))

database relationship laravel eloquent

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

重定向以查看但更改Laravel中的URL

create wizard完成后,我正在尝试将用户重定向回主页。

如果我在控制器中编写return view('main')->with('key'=>'data'),一切都很好,但是URL不会更改为,localhost:8080而是保持为'localhost:8080 / wizard / finish`。

如果我使用redirect('/')->with(['message' => 'Done.'])它重定向到主页,但是因为已经有一个Route::get('/','Controller'),控制器被触发,它返回我的默认主页,没有消息。

 <div class="row">
            <div class="col-12">
                @if (isset($message))
                    <p align="center" style="color: red;"><strong>{{$message}}</strong></p>
                @endif
            </div>
        </div>
Run Code Online (Sandbox Code Playgroud)

编辑:在MainPageController(映射到/)中有一个断点,我看到当重定向到/路由时会触发此控制器。因此,我失去了$message,因为MainPageController还会返回相同的视图,但是没有消息。

redirect view laravel

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

当 ReferencedDomainName 为 NULL 时 LookupAccountName 错误

如果我不将可选值保存ReferencedDomainName在变量中,函数将返回false,并且我无法检索使用的 Sid。如果文档说它是可选的,为什么我还需要包含它?这是我的代码:

这有效并返回一个 SID:

    DWORD size;
    TCHAR lpAccountName[USERNAME_SIZE];
    PSID Sid = (PSID)LocalAlloc(LPTR, SECURITY_MAX_SID_SIZE);
    LPSTR DomainName = (LPSTR)LocalAlloc(LPTR, sizeof(TCHAR) * 1024);
    DWORD cbSid = SECURITY_MAX_SID_SIZE;
    LPSTR userSIDBuffer = (LPSTR)LocalAlloc(LPTR, sizeof(TCHAR) * cbSid);
    SID_NAME_USE peUse;

    size = USERNAME_SIZE;
    if (!GetUserName(lpAccountName, &size))
    {
        _error("Could not retrieve username.");
    }

    printf("Username found: %s\n", lpAccountName);

    size = 1024;
    if (!LookupAccountName(NULL, lpAccountName, Sid, &cbSid, DomainName, &size, &peUse))
    {
        _error("Could not look up account.");
    }

    return Sid;
Run Code Online (Sandbox Code Playgroud)

但是如果我按照 MSDN 文档删除DomainName并更改,我会收到 122 错误并且不会返回任何内容; …

c++ windows winapi msdn

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

python装饰器从装饰函数中获取参数

我有这个代码:

def foo(bar):
    def test(some_string):
        return 'Decorator test: '+bar(some_string)
    return test


def main():
    print(bar('test1'))


@foo
def bar(some_string):
    return some_string[:3]
Run Code Online (Sandbox Code Playgroud)

我知道调用bar('test1)基本上是调用foo(bar('test1')),但当我尝试在其他函数之前打印some_stringfoo,我得到some_string is not defined:

def foo(bar):
    print(some_string)
    def test(some_string):
        return 'Decorator test: '+bar(some_string)
    return test
Run Code Online (Sandbox Code Playgroud)
  1. 如何test知道some_stringfoo没有?
  2. 为什么我必须返回test装饰工作?直接返回Decorator test: '+bar(some_string)不起作用,因为some_string没有定义.

python decorator python-decorators

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