我正在尝试制作一个画廊网站,但我似乎无法检索要在 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_URL和MEDIA_ROOT。我可以从管理员上传图像,它们没问题。
我的MEDIA_URL:
MEDIA_ROOT = os.path.join(BASE_DIR,'static','media')
MEDIA_URL = '/media/'
Run Code Online (Sandbox Code Playgroud)
当我查看 html 时,src路径为空。
我正在尝试在 Digital Ocean 上使用 Nginx 设置 VueJS 前端和 NodeJS api 后端服务器。我在设置 Nginx 使其正常工作时遇到问题。
更详细地讲我想要实现的目标:
实际发生的情况:
配置:
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) 我有一个应用程序,计算你每分钟养殖的黄金.我想制作一个错误报告,不允许您在控制台输入中插入任何文本,您可以在其中插入时间和金币(如下面的代码所示)并显示一些错误消息,如果您这样做并让您重做插入(某种循环或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) 我正在努力寻找一种方法来自动增加节点应用程序的 package.json 。我知道 npm 有一个名为 的脚本version,它接受 3 个参数:minor、major 和 patch,但我未能使用npm version minor例如增量到新版本。
我明白了npm ERR! Git working directory not clean每次我尝试这样做时
所以我想做的是:
在提交之前,我想我必须添加 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 发布。
这是我的程序代码:
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) 我的代码有问题,这是一个简单的骰子游戏:
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)