若有似无的小暗淡

文章 评论 浏览 31

若有似无的小暗淡 2025-02-20 20:41:18

好的,我只是想出来了。

mod segurity启动了。不得不关闭它。

Ok, I just figured it out.

Mod segurity was on. Had to turn it off.

strapi:可以在管理中保存任何东西

若有似无的小暗淡 2025-02-20 07:47:42

您可以使用 frame 标签,

<ScrollViewer>
<Frame content = "{Binding MyPage}"/>
</ScrollViewer>

如果您不想在ViewModel中有一个道具,那么您应该能够

<ScrollViewer>
<Frame>
<Frame.Content>
<locals:MyPage>
</Frame.Content>
</ScrollViewer>

记住您的东西,即 testWindowViewModel 继承页面。这不是ViewModel。相反,这是一个普通的页面。

您需要看起来像这样的东西:

    public class NotifyPropertyClass : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private Page myPage;

        public Page MyPage
        {
            get { return myPage; }
            set
            {
                myPage = value;
                NotifyPropertyChanged();
            }
        }

    }

并且您可以走更远的级别并进行抽象类:

    public abstract class ViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

然后您可以像这样继承ViewModel:

public class TestWindow: Page
{
   public TestWindow()
   {
       InitializeComponent();
    }
}

public class TestWindowViewModel : ViewModel
    {
        private string name;

        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                NotifyPropertyChanged();
            }
        }

        private string description;

        public string Description
        {
            get { return description; }
            set
            {
                Description = value;
                NotifyPropertyChanged();
            }
        }

    }

一旦正确地将其分开,您就可以使用框架并为SomePage和SomePageViewModel,然后您可以在ViewModel的帧内容上使用实际绑定。我知道这很长,但是如果您开始设置一个良好的MVVM设置,那么如果您进入异步,那么您就可以节省自己的头痛,而没有。

You can use a Frame tag

<ScrollViewer>
<Frame content = "{Binding MyPage}"/>
</ScrollViewer>

If you don't want to have a prop in your ViewModel then you should be able to do

<ScrollViewer>
<Frame>
<Frame.Content>
<locals:MyPage>
</Frame.Content>
</ScrollViewer>

Keep in mind you have something called TestWindowViewModel and it inherits Page. This is not a ViewModel. Instead it is a normal page.

You want something that looks like this:

    public class NotifyPropertyClass : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private Page myPage;

        public Page MyPage
        {
            get { return myPage; }
            set
            {
                myPage = value;
                NotifyPropertyChanged();
            }
        }

    }

and you can go a level farther and make an abstract class:

    public abstract class ViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

and then you can just inherit ViewModel like so:

public class TestWindow: Page
{
   public TestWindow()
   {
       InitializeComponent();
    }
}

public class TestWindowViewModel : ViewModel
    {
        private string name;

        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                NotifyPropertyChanged();
            }
        }

        private string description;

        public string Description
        {
            get { return description; }
            set
            {
                Description = value;
                NotifyPropertyChanged();
            }
        }

    }

Once you get this all seperated out correctly you can use the frame and do the same for the SomePage and SomePageViewModel and then you can use actual binding on the Frame Content from the ViewModel. I know this is long winded, but if you start out right on setting up a good MVVM setup you will save yourself headache if you ever get into Async and what not.

将页面作为scrollviewer或contentControl等的内容

若有似无的小暗淡 2025-02-20 02:19:11

我遇到了类似的问题,解决我的案件的解决方案是

  1. 将bind-address更改为从127.0.0.0.1
  2. 将URL的本地主机更改为Localhost:3306

我觉得我们永远不应该放弃,我尝试了这篇文章的所有选择,也来自其他论坛...快乐它有效@saurab

I was experiencing similar problem and the solution for my case was

  1. changing bind-address = 0.0.0.0 from 127.0.0.1
  2. changing url's localhost to localhost:3306

the thing i felt is we should never give up, i tried every options from this post and from other forums as well...happy it works @saurab

求解“通信链接链接失败”与JDBC和MySQL

若有似无的小暗淡 2025-02-19 20:27:58
@Injectable()
export class MyCustomInterceptor implements CacheInterceptor {
  constructor(private reflector: Reflector) {}

  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const myReflectionData = this.reflector.get<string[]>('mykey', context.getHandler());
  //...

或者:

@Injectable()
export class MyCustomInterceptor implements CacheInterceptor {
  @Inject() private reflector: Reflector;

  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const myReflectionData = this.reflector.get<string[]>('mykey', context.getHandler());
  //...
@Injectable()
export class MyCustomInterceptor implements CacheInterceptor {
  constructor(private reflector: Reflector) {}

  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const myReflectionData = this.reflector.get<string[]>('mykey', context.getHandler());
  //...

Or:

@Injectable()
export class MyCustomInterceptor implements CacheInterceptor {
  @Inject() private reflector: Reflector;

  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const myReflectionData = this.reflector.get<string[]>('mykey', context.getHandler());
  //...

在Nestjs上的自定义拦截器中无法使用EEFLECTOR。无法导入模块

若有似无的小暗淡 2025-02-19 20:17:24

我尝试了这样的事情,它起作用了!!

export interface Context {
  tags?: { [Key: string]: string | number | boolean | symbol | null | undefined }
  otherValues?: number 
}

另一种方法是使用记录:

export interface Context {
  tags?: Record<string, string | number | boolean | symbol | null | undefined>
  otherValues?: number 
}

I tried something like this and it worked!!

export interface Context {
  tags?: { [Key: string]: string | number | boolean | symbol | null | undefined }
  otherValues?: number 
}

Also another approach is to use Record:

export interface Context {
  tags?: Record<string, string | number | boolean | symbol | null | undefined>
  otherValues?: number 
}

如何将打字稿索引签名设置为接口内联的值?

若有似无的小暗淡 2025-02-19 08:02:06

您必须解开关注键盘。简单地说,

请将键盘放下键盘使用此隐藏键盘方法。

hideKeyBoard(BuildContext context) {
  FocusScope.of(context).requestFocus(FocusNode());
}

当您敲击后面按钮时,

You have to unfocus Keyboard. In simple words dismiss keyboard

Use it like this

hideKeyBoard(BuildContext context) {
  FocusScope.of(context).requestFocus(FocusNode());
}

call this hide keyboard method when you are tapping on back button.

键盘被解雇后,Textfield仍然集中精力?

若有似无的小暗淡 2025-02-18 15:40:41

如果要包含658368的字符串,请使用以下方式:

#include <QString>
QString displayString(){
    std::string message = "ASD";
    QString result;

    qDebug() << "Message in ASCII Dec : ";
    for(int i=0; i < message.length(); i++) {
        std::cout << (int)message.at(i) << "";
        result += QString::number((int)message.at(i));
    }
    qDebug() << result;
    return result;
}

如果您希望结果在ASCII中转换回ASCII,请

QString::toStdString()

在使用QT Creator时使用QString代替常规字符串,它提供了许多功能强大的功能

If you want a string that contain 658368, use this :

#include <QString>
QString displayString(){
    std::string message = "ASD";
    QString result;

    qDebug() << "Message in ASCII Dec : ";
    for(int i=0; i < message.length(); i++) {
        std::cout << (int)message.at(i) << "";
        result += QString::number((int)message.at(i));
    }
    qDebug() << result;
    return result;
}

If you want your result to get converted back in ASCII, use

QString::toStdString()

Use QString instead of regular string when you use Qt Creator, it provides a lot of powerful function

对于循环输出到QT中的字符串

若有似无的小暗淡 2025-02-18 08:59:07

modal s的discord.js实现有点棘手(或者,如果您有处理按钮的交互经验,等等)。总而言之,当 discordclient 接收到 modal 时,交互不会扩展相同类型的交互您收到 messageComponentIntraction 扩展交互实现InteractionResconses (例如A buttonInteraction (注意subtext:'扩展MessageComponentInteraction') select> selectmenuinteraction 等)。因此, createMessageComponentCollector 永远不会接收交互 s modalSubmitInteraction (请注意subtext:扩展交互的交互实现InteractionRessions - 因为 ModalSubmitInteraction 不是 MessageComponentInteraction (以前的示例 ButtonInteraction selectMenuInteraction 是)。

modalSubmitInteraction modalInteraction messageComponentInteraction button> button Interactraction 。这有意义吗? modalSubmitInteraction MessageComponentInteraction 可以被视为'兄弟姐妹',而 button> buttonInteraction 和/或 selectmenuinteraction 等等。被认为是“ MessageComponentInteraction ”的“孩子”。为了进一步澄清,我会查看模式 s 的文档,因为它为您如何使用discord.js提供了一些上下文。

可能还有其他方法可以处理模态的“集合”,但是在您发布的示例中,我这样做的方式是通过 egaitModalSubmit MessageComponentIntraction MessageComponentIntraction code> 班级。例如:

const fields = {
  age: new TextInputComponent()
    .setCustomId(`age`)
    .setLabel(`What is your age?`)
    .setStyle(`SHORT`)
    .setRequired(true),
    .setPlaceholder(`90 years young`)
  name: new TextInputComponent()
    .setCustomId(`name`)
    .setLabel(`What is your name?`)
    .setStyle(`SHORT`)
    .setRequired(true)
    .setPlaceholder(`John Doe`)
}

const modal = new Modal()
  .setCustomId(`test_modal`)
  .setTitle(`test`)
  .setComponents(
    // Note that unlike how you might expect when sending a Message with Components,
    // MessageActionRows for Modals **can only accept TextInputComponents** (no Buttons or
    // SelectMenus or other Components), and each Action Row can have a maximum of just one
    // TextInputComponent. You can have a maximum of 5 Action Rows in a Modal, so you have
    // a maximum of 5 Text Inputs per Modal.
    new MessageActionRow().setComponents(fields.age),
    new MessageActionRow().setComponents(fields.name),
  )

// Show the Modal to the User in response to the Interaction
await interaction.showModal(modal)

// Get the Modal Submit Interaction that is emitted once the User submits the Modal
const submitted = await interaction.awaitModalSubmit({
  // Timeout after a minute of not receiving any valid Modals
  time: 60000,
  // Make sure we only accept Modals from the User who sent the original Interaction we're responding to
  filter: i => i.user.id === interaction.user.id,
}).catch(error => {
  // Catch any Errors that are thrown (e.g. if the awaitModalSubmit times out after 60000 ms)
  console.error(error)
  return null
})

// If we got our Modal, we can do whatever we want with it down here. Remember that the Modal
// can have multiple Action Rows, but each Action Row can have only one TextInputComponent. You
// can use the ModalSubmitInteraction.fields helper property to get the value of an input field
// from it's Custom ID. See https://old.discordjs.dev/#/docs/discord.js/stable/class/ModalSubmitFieldsResolver for more info.
if (submitted) {
  const [ age, name ] = Object.keys(fields).map(key => submitted.fields.getTextInputValue(fields[key].customId))
  await submitted.reply({
    content: `Your age is ${age}, and your name is ${name}. Hi!`
  })
}

Discord.JS implementation for Modals is a little bit tricky (or at least, unintuitive if you have experience with handling interactions for buttons, etc). To summarize, the Interaction you get when the DiscordClient receives a Modal does not extend the same type of Interaction you get when you receive a MessageComponentInteraction (note the subtext: extends Interaction implements InteractionResponses) (e.g. a ButtonInteraction (note the subtext: 'extends MessageComponentInteraction'), SelectMenuInteraction, etc). As such, the createMessageComponentCollector does not ever receive Interactions that hold a ModalSubmitInteraction (notice the subtext: extends Interaction implements InteractionResponses)-- since a ModalSubmitInteraction is not a MessageComponentInteraction (the former examples ButtonInteraction and SelectMenuInteraction are).

The ModalSubmitInteraction is to a ModalInteraction what a MessageComponentInteraction is to a ButtonInteraction. Does that make sense? ModalSubmitInteraction and MessageComponentInteraction can be considered as 'siblings', while ButtonInteraction and/or SelectMenuInteraction, etc. would be considered as 'children of MessageComponentInteraction'. For further clarification I would take a look at Discord's Documentation for Modals, as it provides some context for how you'd use them with Discord.JS.

There are likely other ways to handle the 'collection' of a Modal, but the way I would do it in the example you posted is through the awaitModalSubmit method on the MessageComponentInteraction class. For example:

const fields = {
  age: new TextInputComponent()
    .setCustomId(`age`)
    .setLabel(`What is your age?`)
    .setStyle(`SHORT`)
    .setRequired(true),
    .setPlaceholder(`90 years young`)
  name: new TextInputComponent()
    .setCustomId(`name`)
    .setLabel(`What is your name?`)
    .setStyle(`SHORT`)
    .setRequired(true)
    .setPlaceholder(`John Doe`)
}

const modal = new Modal()
  .setCustomId(`test_modal`)
  .setTitle(`test`)
  .setComponents(
    // Note that unlike how you might expect when sending a Message with Components,
    // MessageActionRows for Modals **can only accept TextInputComponents** (no Buttons or
    // SelectMenus or other Components), and each Action Row can have a maximum of just one
    // TextInputComponent. You can have a maximum of 5 Action Rows in a Modal, so you have
    // a maximum of 5 Text Inputs per Modal.
    new MessageActionRow().setComponents(fields.age),
    new MessageActionRow().setComponents(fields.name),
  )

// Show the Modal to the User in response to the Interaction
await interaction.showModal(modal)

// Get the Modal Submit Interaction that is emitted once the User submits the Modal
const submitted = await interaction.awaitModalSubmit({
  // Timeout after a minute of not receiving any valid Modals
  time: 60000,
  // Make sure we only accept Modals from the User who sent the original Interaction we're responding to
  filter: i => i.user.id === interaction.user.id,
}).catch(error => {
  // Catch any Errors that are thrown (e.g. if the awaitModalSubmit times out after 60000 ms)
  console.error(error)
  return null
})

// If we got our Modal, we can do whatever we want with it down here. Remember that the Modal
// can have multiple Action Rows, but each Action Row can have only one TextInputComponent. You
// can use the ModalSubmitInteraction.fields helper property to get the value of an input field
// from it's Custom ID. See https://old.discordjs.dev/#/docs/discord.js/stable/class/ModalSubmitFieldsResolver for more info.
if (submitted) {
  const [ age, name ] = Object.keys(fields).map(key => submitted.fields.getTextInputValue(fields[key].customId))
  await submitted.reply({
    content: `Your age is ${age}, and your name is ${name}. Hi!`
  })
}

模态收集器Discord.js

若有似无的小暗淡 2025-02-18 02:04:19

_MSEARCH 查询以这种格式接受身体:

{metadata}
{query}
{metadata}
{query}

您正在尝试发送JSON数组,这就是为什么您会遇到错误的原因。

尝试此(注意,需要第一个空白对象,因为您没有发送任何元数据):

{ }
{"query": {"term": {"name": {"term": "Hulk"}}}},
{"index": "super_heroes"},
{"query": {"term": {"word": {"term": "Iron Man"}}}}

source

The _msearch query accepts body in this format:

{metadata}
{query}
{metadata}
{query}

You're trying to send a JSON array, this is why you get an error.

Try this (note, first blank object is required, since you're not sending any metadata):

{ }
{"query": {"term": {"name": {"term": "Hulk"}}}},
{"index": "super_heroes"},
{"query": {"term": {"word": {"term": "Iron Man"}}}}

Source

在映射索引中无法进行多搜索?

若有似无的小暗淡 2025-02-17 14:18:38

您可以使用 Janitor :: make_clean_names()将列名称转换为同一格式(例如骆驼箱),然后将其转换为rowbind。

例如:

library(data.table)
library(janitor)
ftr <- list.files(path = c("./reports_0", "./reports_1"), 
   pattern = ".*\\.csv$", 
   names = TRUE)

DT <- rbindlist(
  lapply(ftr, function(x) {
    tempDT <- fread(x)
    setnames(tempDT, names(tempDT), janitor::make_clean_names(names(tempDT)))
    return(tempDT)
  }), use.names = TRUE, fill = TRUE)

概念证明

将名称转换为snake_case

> janitor::make_clean_names("Firmware Version")
[1] "firmware_version"
> janitor::make_clean_names("Firmware version")
[1] "firmware_version"

you could use janitor::make_clean_names() to convert columnnames to the same format (for example camelCase), and then rowbind.

for example:

library(data.table)
library(janitor)
ftr <- list.files(path = c("./reports_0", "./reports_1"), 
   pattern = ".*\\.csv
quot;, 
   names = TRUE)

DT <- rbindlist(
  lapply(ftr, function(x) {
    tempDT <- fread(x)
    setnames(tempDT, names(tempDT), janitor::make_clean_names(names(tempDT)))
    return(tempDT)
  }), use.names = TRUE, fill = TRUE)

proof of concept

convert names to snake_case

> janitor::make_clean_names("Firmware Version")
[1] "firmware_version"
> janitor::make_clean_names("Firmware version")
[1] "firmware_version"

使用MAP_DFR时指定哪些列相同

若有似无的小暗淡 2025-02-17 02:02:35
  1. 您ORM配置应该是DataSource的实例
    ormconfig.ts文件
    像这样:

    导出默认新dataSource({
    类型:“ Postgres”,
    主机:process.env.postgres_host
    端口: +process.env.postgres_port,
    用户名:process.env.postgres_user,
    密码:process.env.postgres_db_password,
    数据库:process.env.postgres_database,
    实体:[__dirname +'//* entity {.ts,.js}'],
    同步:false,
    迁移:[__dirname +'/migrations/
    /* {.ts,.js}'],
    });

添加到package.json下一个命令:

"typeorm": "ts-node -P tsconfig.json ./node_modules/typeorm/cli.js",
"db:drop": "yarn run typeorm schema:drop -d src/ormconfig.ts",
"db:gen": "yarn run typeorm migration:generate src/migrations/migration -d src/ormconfig.ts",
"db:migrate": "yarn run typeorm migration:run -- -d src/ormconfig.ts"
  1. You ORM config should be instance of DataSource
    ormconfig.ts file
    like this:

    export default new DataSource({
    type: 'postgres',
    host: process.env.POSTGRES_HOST
    port: +process.env.POSTGRES_PORT,
    username: process.env.POSTGRES_USER,
    password: process.env.POSTGRES_DB_PASSWORD,
    database: process.env.POSTGRES_DATABASE,
    entities: [__dirname + '//*.entity{.ts,.js}'],
    synchronize: false,
    migrations: [__dirname + '/migrations/
    /*{.ts,.js}'],
    });

add to package.json next commands:

"typeorm": "ts-node -P tsconfig.json ./node_modules/typeorm/cli.js",
"db:drop": "yarn run typeorm schema:drop -d src/ormconfig.ts",
"db:gen": "yarn run typeorm migration:generate src/migrations/migration -d src/ormconfig.ts",
"db:migrate": "yarn run typeorm migration:run -- -d src/ormconfig.ts"

对象文字只能指定已知属性,并且CLI&#x27; Type typeormoduleoptions中不存在

若有似无的小暗淡 2025-02-16 09:49:51

使用 flex-wrap:wrap; 当没有DIV空间时,DIV包裹到下一行。

我也使用 Jusify-content:space-betew; 填充屏幕的整个宽度

.container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  flex-wrap: wrap;
}
<div class="container">
  <div>pippo</div>
  <div>pluto</div>
  <div>paperino</div>
  <div>topolino</div>
</div>

with flex-wrap: wrap; when there was no space for div, div wrap to the next line.

also i use justify-content: space-between; to fill up the whole width of the screen

.container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  flex-wrap: wrap;
}
<div class="container">
  <div>pippo</div>
  <div>pluto</div>
  <div>paperino</div>
  <div>topolino</div>
</div>

Divs的响应设计

若有似无的小暗淡 2025-02-15 23:31:17

它与Conda提供的Python有关。

标志“ -B/HOME/PAVAN/MINICONDA3/ENVS/CODELAB/COPILER_COMPAT”将要求Crumplier从该路径中拾取LD。但是,当您使用不同的编译器工具链时,Conda提供的LD会引起一些问题。

步骤修复它:

cd /home/pavan/miniconda3/envs/codelab/compiler_compat
rm -f ld
ln -s /usr/bin/ld ld

并尝试再次构建mpi4py。

之后,撤销了这种变化:

cd /home/pavan/miniconda3/envs/codelab/compiler_compat
rm -f ld
ln -s ../bin/x86_64-conda-linux-gnu-ld ld

It was related to python provided by conda.

the flag "-B /home/pavan/miniconda3/envs/codelab/compiler_compat" will ask the complier to pick up ld from that path. but the ld provided by conda will cause some issue when you are using different compiler toolchains.

step to fix it:

cd /home/pavan/miniconda3/envs/codelab/compiler_compat
rm -f ld
ln -s /usr/bin/ld ld

and try to build mpi4py again.

after that, revoke that change:

cd /home/pavan/miniconda3/envs/codelab/compiler_compat
rm -f ld
ln -s ../bin/x86_64-conda-linux-gnu-ld ld

无法使用PIP安装mpi4py

若有似无的小暗淡 2025-02-15 15:22:51

从表单中接受文件时,与 request.post 一起,您还应提取 request.files ...

form = ProductCreationForm(request.POST, request.FILES)

顺便说一句, create> create(name =名称,价格=价格,图像=图像)已经保存了该项目,因此无需调用保存方法 new_item.save()

仅使用模型表单而更容易。因此,我只是在此处更新您的代码...

models.py 文件:

class Product(models.Model):
    name = models.CharField(max_length=250)
    price = models.FloatField(default=0)
    image = models.ImageField(upload_to='image_uploads/', null=True, blank=True)

forms.py file:

from .models import Product
from django import forms
from django.utils.translation import gettext_lazy as _

class ProductCreationForm(forms.ModelForm):
    class Meta:
         model = Product
         fields = "__all__"
         labels = {
              "name": _("Product Name"), 
              "price": _("Price"), 
              "image": _("Image"),
         }
         required = (
              'name',
              'price',
              'image',
         )

然后在 views.pys.py 文件:

if request.method == "POST":
     form = ProductCreationForm(request.POST, request.FILES)

     if form.is_valid():
          form.save()  # This here will save the necessary data to the database
     else:
          print(form.errors)  # To show you what field(s) are causing the form not to submit

     return redirect('shelf')

最后,操作 form> form> form tag 不需要属性,因此您可以将其删除,因为相同的函数将处理发布请求

此外,请确保在您的 street.py 文件中,您为 Media_url Media_root

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

在您的项目的 urls.py中 设置了一些设置。 文件:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
     ...
]

if settings.DEBUG:
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

When accepting files from forms, along with request.POST, you should also fetch request.FILES as well...

form = ProductCreationForm(request.POST, request.FILES)

By the way, the create(name=name, price=price, image=image) already saved the item so there's no need to call the save method new_item.save().

It would be easier to just work with a model form instead. So I'm just updating your code here...

models.py file:

class Product(models.Model):
    name = models.CharField(max_length=250)
    price = models.FloatField(default=0)
    image = models.ImageField(upload_to='image_uploads/', null=True, blank=True)

forms.py file:

from .models import Product
from django import forms
from django.utils.translation import gettext_lazy as _

class ProductCreationForm(forms.ModelForm):
    class Meta:
         model = Product
         fields = "__all__"
         labels = {
              "name": _("Product Name"), 
              "price": _("Price"), 
              "image": _("Image"),
         }
         required = (
              'name',
              'price',
              'image',
         )

Then within your view in the views.py file:

if request.method == "POST":
     form = ProductCreationForm(request.POST, request.FILES)

     if form.is_valid():
          form.save()  # This here will save the necessary data to the database
     else:
          print(form.errors)  # To show you what field(s) are causing the form not to submit

     return redirect('shelf')

Finally, the action attribute is not needed on your form tag, so you can remove it since the same function will be handling the post request.

Additionally, ensure that in your setting.py file you have something set for the MEDIA_URL and the MEDIA_ROOT

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

In your project's urls.py file:

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
     ...
]

if settings.DEBUG:
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

如何收集图像文件并将其保存在数据库中

若有似无的小暗淡 2025-02-15 09:36:28

只需删除:

.home {
    position: absolute;
    top: 0px;
    left: 0px;
}

.home video {
    position: absolute;
    top: 0;
    left: 0;
}

.footer {
    position: relative;
    top: 1000;
    left: 0;
}

使用位置:绝对位置:固定告诉Web浏览器不是 “保留”文档结构中的“储备”空间,并使您的页脚漂浮在视频上方。 According to https://www.impressivewebs.com/css-things -dont-occupy空间/ - 这些元素是从文档流中取出的,因此以源顺序出现在它们之后的元素不会在它们周围或以下流动。

< a href =“ https://i.sstatic.net/w897l.jpg” rel =“ nofollow noreferrer”>

您有一个简单的布局并注意 - div是将所有页面的宽度划分为默认和stack 一个 的元素,所以不要使用此处的任何定位(覆盖除外)。

这样的事情应该起作用(需要做的很小的改进):

* {
    margin: 0;
}

.home {
    min-height: 100vh;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #111;
    color: #fff;
    z-index: 2;
}

.home video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1.0;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0.0, 0.0, 0.0, 0.4);
}

.footer {
    height: 400px;
    z-index: 50;
    background: aqua;
}

Just remove:

.home {
    position: absolute;
    top: 0px;
    left: 0px;
}

.home video {
    position: absolute;
    top: 0;
    left: 0;
}

.footer {
    position: relative;
    top: 1000;
    left: 0;
}

Using position: absolute or position: fixed tells web browser to not "reserve" space in document structure for this element and makes your footer floating above video. According to https://www.impressivewebs.com/css-things-that-dont-occupy-space/ - These elements are taken out of the document flow, so elements that appear after them in the source order will not flow around or below them.

absolutepositioning

You have a simple layout and take a notice - div's are elements that takes all of the page's width by default and stack one under another so don't use any positioning here (except for overlay).

Something like this should work (with small improvements to do):

* {
    margin: 0;
}

.home {
    min-height: 100vh;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #111;
    color: #fff;
    z-index: 2;
}

.home video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1.0;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0.0, 0.0, 0.0, 0.4);
}

.footer {
    height: 400px;
    z-index: 50;
    background: aqua;
}

如何添加页脚或任何其他内容的bellow视频,该视频占屏幕高度的100%?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文