我想使用图像文件作为背景图像Django.但是我不知道怎么做.首先,我读了这篇文章并尝试在css文件中写下这样的内容.
#third{
background: url("img/sample.jpeg") 50% 0 no-repeat fixed;
color: white;
height: 650px;
padding: 100px 0 0 0;
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
{% load staticfiles %}
#third{
background: url({% static "img/sample.jpeg" %}) 50% 0 no-repeat fixed;
}
Run Code Online (Sandbox Code Playgroud)
和
#third{
background: url("../img/sample.jpeg") 50% 0 no-repeat fixed;
}
Run Code Online (Sandbox Code Playgroud)
也不行.
当你在css文件上使用background-image时,你通常如何编写css文件?你能给我一些建议吗?
C:\~~~~~~> dir hello\static\img
2016/09/28 19:56 2,123 logo.png
2016/09/24 14:53 104,825 sample.jpeg
C:\~~~~~~> dir hello\static\css
2016/09/29 20:27 1,577 site.css
C:\~~~~~~> more lemon\settings.py
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') …Run Code Online (Sandbox Code Playgroud) 我解决这个问题。
我需要将字符串转换为 int。在这种情况下,我需要将“5 2 4 6 1 3”转换为例如[6]int{5,2,4,6,1,3}。我按照这段代码编写,特别是AizuArray(). 看来 elements 在这里。请告诉我我的方法是否正确?或者你能告诉我更好的方法吗?我问这个是因为我觉得我的方式是多余的,而Java方式要容易得多。谢谢。
package main
import (
"fmt"
"reflect"
"strconv"
"strings"
)
func AizuArray(A string, N string) []int {
a := strings.Split(A, " ")
n, _ := strconv.Atoi(N) // int 32bit
b := make([]int, n)
for i, v := range a {
b[i], _ = strconv.Atoi(v)
}
return b
}
func main() {
A := "5 2 4 6 1 3"
N := "6" …Run Code Online (Sandbox Code Playgroud) 我按照这些代码编写了用于消息功能的Ajax. 当我填
<script>alert("Django+Ajax");</script>
Run Code Online (Sandbox Code Playgroud)
在表单中并提交,警报出现在我的浏览器上。我想逃避输出,但我不知道该怎么做。你能给我一些建议吗?
消息.html
<html>
<head>
<style type="text/css">
div#message_form {
display: none;
margin: 25px;
padding: 25px;
background: #eee;
width: 200px;
height: 180px;
}
</style>
</head>
<body>
<input type="button" id="message" value="message"> <br />
<div id="message_form">
<form id="post_message" method="POST" action="">
{% csrf_token %}
title: {{ form.title }} <br />
body: {{ form.body }} <br />
<input type="submit" value="send">
<input type="reset" value="reset">
</form>
</div>
<div id="get_title"></div>
<div id="get_body"></div>
{% load staticfiles %}
<script type="text/javascript" src="{% static "myapp/js/jQuery.js" %}"></script>
<script type="text/javascript" …Run Code Online (Sandbox Code Playgroud) 这是我的models.py:
class Group_Photo(models.Model):
group_id = models.ForeignKey(Group)
photo = models.ImageField(upload_to="static/image/group/" + group_id + "/")
Run Code Online (Sandbox Code Playgroud)
我想将图像上传到一个组的目录.例如,如果group_id = 3,
upload_to="static/image/group/3/"
我应该怎么做?
对不起,这是错误.
文件"/models.py",第161行,在Group_Photo中photo = models.ImageField(upload_to ="static/image/group /"+ group_id +"/")TypeError:无法隐式地将'ForeignKey'对象转换为str
我是初学者Go.我写了这段代码,但发生了错误.我该如何编写包含string和[]string属性的地图?
package main
import (
"fmt"
)
func main() {
prof := make(map[string]map[string]interface{})
prof["me"] = map[string]string{
"name": "John Lennon",
"email": "foobar@gmail.com",
"phone": "090-0000-0000",
"occupation": []string{"Programmer", "System Engineer"},
"language": []string{"Go", "Java", "Python", "PHP", "JavaScript", "SQL"},
"hobby": []string{"Photography", "Traveling", "Fishing", "Eating"},
}
fmt.Println(prof)
}
Run Code Online (Sandbox Code Playgroud)
此错误来自Ideone.
# _/home/NcWlmE
./prog.go:14: cannot use []string literal (type []string) as type string in map value
./prog.go:15: cannot use []string literal (type []string) as type string in map value
./prog.go:16: …Run Code Online (Sandbox Code Playgroud)