我正在尝试将VueJS与我的Django应用程序的前端集成.我在javascript文件中有以下Vue代码:
window.onload = function() {
Vue.component('discuss-post', {
props: ['post'],
template: `<div class="card">
<div class="grid-x margin-x">
<div class="cell small-4">
<img class="avatar-img" :src="post.by.profile.img_url">
<p style="font-family: Abel;font-size: 24px">{{ post.by }}</p>
</<div>
</div>
<div class="grid-x margin-x">
<div class="cell small-4">
<p style="font-family: Abel;font-size: 18px">{{ post.content }}</p>
</div>
</div>
</div>`
})
var postDiv = new Vue({
el: "#post-div"
})
}
Run Code Online (Sandbox Code Playgroud)
以及HTML文件中的以下代码:
<div class="card-section">
{% for feed in feeds %}
{% for post in feed %}
<div id="post-div">
<discuss-post post="{{ post }}"></discuss-post>
</div>
{% endfor %}
{% …Run Code Online (Sandbox Code Playgroud) 我的程序计算数学常数e,这是不合理的.为了做到这一点,我需要得到非常大数的阶乘.
int无法处理大于170的数字!(我发现Google最大的计算器可以处理的是170.654259,但我不确定非整数是如何分解的.) float也无法处理非常大的数字.
我计算e到750000位数,math.factorial(750000)是一个令人难以置信的大数字.然而,Decimal处理它很容易.
Decimal在OverflowError提出之前,一个数字有多大?Python 2与Python 3的大小不同吗?
我是Java编程语言的新手,对数组有疑问.String[]数组包含字符串.Array[]数组包含其他数组.Object[]阵列怎么样?显然,这些将持有Object.但是,既然Object是Java中所有东西的超类,这是否意味着Object[]数组可以容纳ObjectJava中的所有类型?换句话说,数组是否可以保存作为创建数组的对象的子类的对象?一个可以Number[]阵列持有的整数?
我不想提出一个新问题,尽管已经就同一主题提出了很多问题,但我确实不知道为什么这不起作用。
我尝试使用以下代码创建 JSON 对象:
var p = JSON.stringify(decodeJSON('{{post.as_json}}'))
var post = JSON.parse(p);
console.log(post); // Debug log to test if code is valid
Run Code Online (Sandbox Code Playgroud)
和decodeJSON功能:
function decodeJSON(json) {
var txt = document.createElement("textarea");
txt.innerHTML = json;
return txt.value.replace(/u'/g, "'");
}
Run Code Online (Sandbox Code Playgroud)
console.log(post)返回以下 JSON 字符串:
{'content': 'kj fasf', 'uid': '4eL1BQ__', 'created': '07/09/2017', 'replies': [], 'tags': ['python'], 'by': {'username': 'Dorian', 'img_url': '/static/imgs/user_Dorian/beaut.jpg'}, 'likes': 0}
Run Code Online (Sandbox Code Playgroud)
扫描完字符串后,我非常确定 JSON 是有效的并且没有语法错误。但是,当运行时JSON.parse(p),我得到的不是一个对象,而是一个字符串。可能是什么原因?
我在Python 3.4 shell中使用转义反斜杠进行了一些实验,并注意到一些非常奇怪的事情.
>>> string = "\test\test\1\2\3"
>>> string
'\test\test\x01\x02\x03'
>>> string = "5"
>>> string
'5'
>>> string = "5\6\7"
>>> string
'5\x06\x07'
Run Code Online (Sandbox Code Playgroud)
正如您在上面的代码中看到的,我将变量字符串定义为"\test\test\1\2\3".但是,当我进入string控制台而不是打印时"\test\test\1\2\3",它会打印出来"\test\test\x01\x02\x03".为什么会发生这种情况,它用于什么?
我正在学习如何使用 python*args*和**kwargs符号。我正在尝试使用 getattr 将可变数量的参数传递给另一个文件中的函数。
以下代码将接受控制台输入,然后搜索包含放入控制台的函数的模块,然后使用参数执行该函数。
while True:
print(">>>", end = " ")
consoleInput = str(input())
logging.info('Console input: {}'.format(consoleInput))
commandList = consoleInput.split()
command = commandList[0]
print(commandList) # Debug print
"""Searches for command in imported modules, using the moduleDict dictionary,
and the moduleCommands dictionary."""
for key, value in moduleCommands.items():
print(key, value)
for commands in value:
print(commands, value)
if command == commands:
args = commandList[0:]
print(args) # Debug print
print(getattr(moduleDict[key], command))
func = getattr(moduleDict[key], command, *args)
func()
output = …Run Code Online (Sandbox Code Playgroud) 我已阅读 Jinja 文档并正在使用truncate过滤器。我完全按照文档中的定义使用它。
从文档:
truncate(s, length=255, killwords=False, end='...', leeway=None) 返回字符串的截断副本。长度由第一个参数指定,默认为 255。如果第二个参数为真,过滤器将按长度剪切文本。否则它将丢弃最后一个字。如果文本实际上被截断,它将附加一个省略号(“...”)。如果你想要一个不同于“...”的省略号,你可以使用第三个参数来指定它。长度仅超出第四个参数中给出的容差范围的字符串将不会被截断。
这是我的代码:
{% if post.replies.all %}
<ul class="accordion" data-accordion data-multi-Expand="true" data-allow-all-closed="true">
{% for reply in post.replies.all %}
<li class="accordion-item" data-accordion>
<a href="#" class="accordion-title">{{reply.by}}: {{reply.content|truncate(14)}}</a>
<div class="accordion-content" data-tab-content>
<img src="{{ reply.by.profile.img_url }}" class="thumbnail" width="50" height="50">
<p>{{ reply.content }}</p>
</div>
</li>
{% endfor %}
</ul>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
测试后我得到以下回溯:
我究竟做错了什么?
我正在学习Python编程.我的任务是使用这些值创建两个词典:
prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15
}
Run Code Online (Sandbox Code Playgroud)
我的任务是以这种格式打印关于字典的东西:我应该使用FOR循环来访问数据.
apple
price: 2
stock: 0
Run Code Online (Sandbox Code Playgroud)
说明书说,由于两个词典具有相同的"键",我可以同时访问它们.但是我不知道这意味着什么.到目前为止学习Python已经轻而易举,但这让我很难过.
python ×5
django ×2
javascript ×2
python-3.x ×2
arrays ×1
decimal ×1
dictionary ×1
html ×1
java ×1
jinja2 ×1
json ×1
python-2.x ×1
string ×1
traceback ×1
vuejs2 ×1