小编Chr*_*ris的帖子

Django错误:无法解析余数:':'Ymd"'来自'post.date | date:"Ymd"'

我正在创建一篇博客文章,在成功迁移我的博客文件后,当我访问我网站的博客页面时,我返回了一个错误(无法解析剩余部分:':'ymd''来自'post.date | date: "年月日"")

我似乎无法找到这是语法错误还是逻辑错误

HTML:

{% extends "personal/header.html" %}

{% block content %}

    {% for post in object_list %}

    <h5> {{ post.date|date: "Y-m-d"}} <a href="/blog/{{ post.id }}"> {{ post.title }} </a> </h5>

    {% endfor %}

{% endblock %}
Run Code Online (Sandbox Code Playgroud)

Python(models.py):

from django.db import models

class Post (models.Model):
    title = models.CharField(max_length=140)
    body = models.TextField()
    date = models.DateTimeField()

    def __unicode__(self):
        return self.title
Run Code Online (Sandbox Code Playgroud)

django django-models python-2.7

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

在 Swift 中使用正则表达式

我正在尝试替换 Swift 中字符串中出现的所有空格和特殊字符。

我不知道 Swift 中的正则表达式是什么。

我尝试使用内置函数 .replacingOccurences(of:) 并将我的 RegEx 作为字符串协议传递,在代码编译时,不进行任何更改。

网上有很多关于如何替换 Swift 中的事件的资源,但是,解决方案比看起来需要的要复杂得多。

如何正确返回此输出(当前策略):

let word = "Hello World!!"
func regEx(word: String) -> String {
   return word.replacingOccurrences(of: "/[^\\w]/g", with: "")
}
// return --> "HelloWorld"
Run Code Online (Sandbox Code Playgroud)

regex string swift

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

标签 统计

django ×1

django-models ×1

python-2.7 ×1

regex ×1

string ×1

swift ×1