我正在尝试获取漫画书问题的下一个和前一个对象.简单地更改ID号或过滤添加日期是行不通的,因为我没有按顺序添加问题.
这是我的视图设置的方式,它的工作原理prev_issue和返回前一个对象,但它返回最后一个对象next_issue,我不知道为什么.
def issue(request, issue_id):
issue = get_object_or_404(Issue, pk=issue_id)
title = Title.objects.filter(issue=issue)
prev_issue = Issue.objects.filter(title=title).filter(number__lt=issue.number)[0:1]
next_issue = Issue.objects.filter(title=title).filter(number__gt=issue.number)[0:1]
Run Code Online (Sandbox Code Playgroud) 我在Twitter上使用弹出窗口直接链接分享按钮:
<a href="https://twitter.com/intent/tweet?url=<?php echo urlencode(get_permalink());?>&text=<?php echo get_the_title(); ?>&via=username" target="_blank"
有了所有疯狂的社交媒体插件,这是我实现共享按钮最简单,最直接的方式.
但是,当&标题中有标题时,标题将破坏应该显示状态的文本.我知道你需要urlencode()标题,但是当我这样做时,它会在状态信息中显示特殊字符.
既然你现在不需要在Twitter中共享+一个[space],我需要替换任何&一个&.但是,它似乎没有用str_replace().它由于某些原因输出HTML特殊字符.做某事<?php echo str_replace('&', '&', urldecode(get_the_title())); ?>也不起作用.
我正在尝试对基于类的视图进行分页.以下是我的观点:
class IssuesByTitleView(ListView):
context_object_name = "issue_list"
def issues(request):
issue_list = Issue.objects.all()
###### Commented out does not work ######
# paginator = Paginator(issue_list, 24)
# try:
# page = int(request.GET.get('page', '1'))
# except ValueError:
# page = 1
# try:
# issues = paginator.page(page)
# except (EmptyPage, InvalidPage):
# issues = paginator.page(paginator.num_pages)
def get_queryset(self):
self.title = get_object_or_404(Title, slug=self.kwargs['title_slug'])
return Issue.objects.filter(title=self.title).order_by('-number')
def get_context_data(self, **kwargs):
context = super(IssuesByTitleView, self).get_context_data(**kwargs)
context['title'] = self.title
return context
Run Code Online (Sandbox Code Playgroud)
以下是我的模型的一些示例:
class Title(models.Model):
CATEGORY_CHOICES = (
('Ongoing', 'Ongoing'),
('Ongoing …Run Code Online (Sandbox Code Playgroud) 我已经为此搜索了所有内容,但找不到任何东西。
我有一个结构体,它接收 ahttp.Client并发送几个 GET 请求。在我的测试中,我想模拟响应,因此它不会发送真正的请求。
目前我已经想出了如何只处理 1 个请求,如下所示:
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
file, err := os.Open("./testdata/1.html")
if err != nil {
t.Error(err)
}
bytes, err := ioutil.ReadAll(file)
if err != nil {
t.Error(err)
}
w.Write(bytes)
}))
ts.Client() // Now I can inject this client into my struct.
Run Code Online (Sandbox Code Playgroud)
因此,一旦该响应被模拟出来并且 http 客户端执行一个新请求,我的测试就会在此之后发送真正的请求。
如何允许多个处理程序,以便在调用时模拟多个响应http.Client.Get(...)?
我已经重新创建了我使用CSS font-family和Chrome for Android的问题.Web浏览器不会正确继承字体,而是使用后备字体.
http://jsbin.com/iyifah/1/edit
这似乎是已经在Google上发票的错误(http://code.google.com/p/chromium/issues/detail?id=138257).
添加<meta name="viewport" content="width=device-width, initial-scale=1" />到HTML应该可以解决问题,但这只能解决第一个元素的设置字体问题.
JS Bin链接将有助于解释我在说什么.所以,如果有人使用Chrome for Android,请转到链接查看我在说什么!
谢谢.
我的docker-compose.yml文件:
version: "3.1"
services:
redis:
container_name: my_redis
image: redis:4.0.8-alpine
ports:
- "6379:6379"
volumes:
- ./docker/data/:/data
- ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf
Run Code Online (Sandbox Code Playgroud)
当我运行时docker-compose up --build,这是我得到的错误:
Can't chdir to '/var/lib/redis': No such file or directory
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?似乎唯一有效的情况是我不安装配置文件,但我需要自己的配置文件。
Google可以识别<image>XML网站地图的标签(http://support.google.com/webmasters/bin/answer.py?hl=zh_CN&answer=178636),我想在我的网站地图中添加图片属性。
因此,需要这样的操作才能获取cover_image,然后将其加载到xml文件中:
for article in articles:
print article.cover_image
Run Code Online (Sandbox Code Playgroud)
我还需要article.title为<image:title>代码加载。
我已经Google搜索并搜索了Stack Overflow作为示例,但令人惊讶的是我找不到任何东西,因此非常感谢帮助。
到目前为止,我的文件:
## sitemaps.py ##
from django.contrib.sitemaps import Sitemap
from myproject.article.models import Article
class ArticleSitemap(Sitemap):
priority = 1.0
def items(self):
return Article.objects.order_by('-id').order_by('-pub_date')
def lastmod(self, obj):
return obj.pub_date
## urls.py ##
from myproject.sitemaps import ArticleSitemap
sitemaps = {
"article": ArticleSitemap
}
urlpatterns += patterns ('',
(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})
Run Code Online (Sandbox Code Playgroud) 我正在寻找一组基本的文件权限,以使django安装尽可能安全.
我似乎无法在Django网站或Google上找到任何明显的参考.
有任何链接或线索吗?
我使用Apache + mod_wsgi + django.我没有上传目录的权限.这是一个非常基本的设置.
我正在运行我的代码,因此:
/var/www/djangodir
/django
/3rdpartyapp
/myapp
/serverfiles/my.wsgi
all directorys: 755 owned by root.root
all files: 644 owned by root.root
exceptions to all files
-----------------------
settings.py file: 400 owned by apache.apache
my.wsgi: 400 owned by apache.apache
Run Code Online (Sandbox Code Playgroud)
我不喜欢所有文件上的644,并且想要收紧它,但似乎无法逃脱400或500.如果我这样做,wsgi应用程序无法从django导入任何东西.
救命!
我想Node从 Go 中的链表中删除 a,我有这个结构体和这些方法:
type Node struct {
Next *Node
Val int
}
func (n *Node) Append(val int) {
end := &Node{Val: val}
here := n
for here.Next != nil {
here = here.Next
}
here.Next = end
}
func Remove(n *Node, val int) *Node {
head := n
for head.Next != nil {
if head.Next.Val == val {
head.Next = head.Next.Next
return head
}
head = head.Next
}
return head
}
func NewNode(val int) *Node {
return …Run Code Online (Sandbox Code Playgroud) 我有一个Google Spreadsheet,我想用Python获取,然后通过JSON处理它.它已经完成了一半,在浏览Stackoverflow几个小时后,我认为是时候提问了.
例如,JSON文件的格式如下所示(来自https://developers.google.com/gdata/docs/json).
{
"version": "1.0",
"encoding": "UTF-8",
"feed": {
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
"xmlns$gd": "http://schemas.google.com/g/2005",
"xmlns$gCal": "http://schemas.google.com/gCal/2005",
"id": {"$t": "..."},
"updated": {"$t": "2006-11-12T21:25:30.000Z"},
"title": {
"type": "text",
"$t": "Google Developer Events"
},
"subtitle": {
"type": "text",
"$t": "The calendar contains information about upcoming developer
conferences at which Google will be speaking, along with other
developer-related events."
},
"link": [{
"rel": "...",
"type": "application/atom+xml",
"href": "..."
},{
"rel": "self",
"type": "application/atom+xml",
"href": "..."
}],
"author": [{
"name": {"$t": …Run Code Online (Sandbox Code Playgroud) python json google-sheets google-spreadsheet-api python-requests