小编Vic*_*tor的帖子

在 django 中检索图像

我正在尝试制作一个画廊网站,但我似乎无法检索要在 html 中显示的图像。我正在尝试根据filter_type具有图像价值的数据库检索图像。

到目前为止我有这个:

views.py

def gallery(request):
    img = Upload.objects.filter(file_type='image')
    return render(request,'gallery.html',{"img":img})
Run Code Online (Sandbox Code Playgroud)

并在html

{% for n in img %}
        <img src="{{ n.img}}" />
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

models.py的如下:

class Upload(models.Model):
    image = models.ImageField(upload_to='media/image',default='')
    text_field = models.CharField(max_length=200,default='')
    date_added = models.DateTimeField(auto_now_add=False,auto_now=True)
    file_type = models.CharField(max_length=256, choices=[('image', 'image'), ('video', 'video'), ('other', 'other')])
    class Meta:
        verbose_name_plural = "Files Manager"
Run Code Online (Sandbox Code Playgroud)

我还设置了MEDIA_URLMEDIA_ROOT。我可以从管理员上传图像,它们没问题。

我的MEDIA_URL

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

MEDIA_URL = '/media/'
Run Code Online (Sandbox Code Playgroud)

当我查看 html 时,src路径为空。

html python django

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

Nginx 意外地为 Nodejs API 返回 404

我正在尝试在 Digital Ocean 上使用 Nginx 设置 VueJS 前端和 NodeJS api 后端服务器。我在设置 Nginx 使其正常工作时遇到问题。

更详细地讲我想要实现的目标:

  • 访问 http://ipaddressordomain/ - 返回 Vuejs 应用程序。
  • VueJS 应用程序需要从位于 http://ipaddressordomain/api 的后端发送和提取数据,Nodejs api 在同一服务器上的端口 3333 上工作。

实际发生的情况:

  • 访问 http://ipaddressordomain/ - 返回 Vuejs 应用程序,没有问题。VueJS 似乎工作正常。
  • Vuejs 无法连接后端 api。同样通过浏览器或 Postman 访问 http://ipaddressordomain/api 返回 404。

配置

NodeJS api 路由可用路由应该是端口 3333 上的 http://myaddress/api:

router.route("/api/:sid").get(getUrlShorten);
router.route("/ai").post(postUrlShorten);
Run Code Online (Sandbox Code Playgroud)

Nginx 配置:

Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 …
Run Code Online (Sandbox Code Playgroud)

nginx node.js digital-ocean vue.js

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

仅允许插入数字并将小时数转换为分钟以计算黄金/分钟 - 更新

我有一个应用程序,计算你每分钟养殖的黄金.我想制作一个错误报告,不允许您在控制台输入中插入任何文本,您可以在其中插入时间和金币(如下面的代码所示)并显示一些错误消息,如果您这样做并让您重做插入(某种循环或if/else的事情......)希望我清楚自己,你是我的新手......所以我希望你理解.到目前为止,这是我的代码:------------------------------- //////////
更新问题,因为我不想为同一个代码提出一个新问题:
我如何在这段代码中将我的小时转换为分钟,1.2小时的浮动计算将计算为72分钟而不是80分.(我在下面发表评论在代码中的问题是)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YourGold
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to YourGold App! \n------------------------");
            Console.WriteLine("Inesrt your gold: ");
            int gold = int.Parse(Console.ReadLine());
            Console.WriteLine("Your gold is : " + gold);
            Console.WriteLine("Inesrt your time(In Hours) played: ");
            float hours = float.Parse(Console.ReadLine());
            int minutes = 60;
            float time = (float)hours * minutes; // Here the calculation are wrong...
            Console.WriteLine("Your total time playd is : " + time + " …
Run Code Online (Sandbox Code Playgroud)

c#

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

使用git推送自动增加nodejs包中的应用程序版本

我正在努力寻找一种方法来自动增加节点应用程序的 package.json 。我知道 npm 有一个名为 的脚本version,它接受 3 个参数:minor、major 和 patch,但我未能使用npm version minor例如增量到新版本。

我明白了npm ERR! Git working directory not clean每次我尝试这样做时

所以我想做的是:

  1. 我有一个带有 package.json 文件的节点应用程序,其版本从 0.0.1 开始。
  2. 致力于新功能或错误修复或其他任何事情,然后我正在创建一个新分支并希望将我的更改推送到 git。
  3. 现在是困难的部分:

在提交之前,我想我必须添加 json 包。推送到 git 时如何自动增加值?正如我现在所说,它将是 0.0.1 版本,如下所示:

{
  "name": "App name",
  "version": "0.0.1",
   ...
}
Run Code Online (Sandbox Code Playgroud)

对于新的提交,假设这是一个次要版本,它应该是:

{
  "name": "App name",
  "version": "0.0.2",
   ...
}
Run Code Online (Sandbox Code Playgroud)

此外,这个应用程序不会发布在 NPM 包存储库上,因此我不需要 npm 发布。

versioning git node.js npm

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

程序行为在不同系统上是不同的.为什么?

这是我的程序代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YourGold
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to YourGold App! \n------------------------");
            Console.WriteLine("Inesrt your gold: ");
            int gold;
            while (!int.TryParse(Console.ReadLine(), out gold))
            {
                Console.WriteLine("Please enter a valid number for gold.");
                Console.WriteLine("Inesrt your gold: ");
            }
            Console.WriteLine("Inesrt your time(In Hours) played: ");
            float hours;
            while (!float.TryParse(Console.ReadLine(), out hours))                
                    {
                        Console.WriteLine("Please enter a valid number for hours.");
                        Console.WriteLine("Inesrt your hours played: ");
                    }
                    float time = ((int)hours) * 60 …
Run Code Online (Sandbox Code Playgroud)

c#

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

Java Dice游戏无法正常工作。需要一些建议

我的代码有问题,这是一个简单的骰子游戏:

import java.util.Random;
class Zaruri {
    public static void main(String args[]) {
        Random roll = new Random();
        int[] zar = new int[2];

            for (int i = 0; i < 1; i++)  {
                for(int k = 0; k < 2; k++){
                zar[i] = (int) (roll* 6) + 1;
            }
            if (zar[0] == zar[1]) {
                System.out.println("Your numbers are : " + zar[0] + " and " + zar[1]  + "\nYou won! \nYEEEY!!");

            } else {
                System.out.println("Your numbers are : " + zar[0] …
Run Code Online (Sandbox Code Playgroud)

java random

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

标签 统计

c# ×2

node.js ×2

digital-ocean ×1

django ×1

git ×1

html ×1

java ×1

nginx ×1

npm ×1

python ×1

random ×1

versioning ×1

vue.js ×1