我是django的新手.我坚持在模板中比较字符串的问题.
我使用ifnotequal标签来比较字符串.但它没有用.
我试着输出变量:
{{ request.user.username }}
{{ article.creator }}
Run Code Online (Sandbox Code Playgroud)
在这里我比较:
{% ifnotequal request.user.username article.creator %}
{# output something #}
{% endifnotequal %}
Run Code Online (Sandbox Code Playgroud)
但是当我做硬编码时:它有效.
{% ifnotequal "justin" "mckoy" %}
{# output something #}
{% endifnotequal %}
Run Code Online (Sandbox Code Playgroud)
问题是什么?它article.creator来自数据库,user.username来自请求.
任何人都可以帮我解决这个问题吗?
我想突出显示您点击的当前菜单.我正在使用CSS,但它现在正在运行.
这是我的css代码:
#sub-header ul li:hover{ background-color: #000;}
#sub-header ul li:hover a{ color: #fff; }
#sub-header ul li.active{ background-color: #000; }
#sub-header ul li.active a{ color: #fff; }
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<div id="sub-header">
<ul>
<li> <a href="index.php">Home</a> </li>
<li> <a href="contact.php">Contact Us</a> </li>
<li> <a href="about.php">About Us</a> </li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
当我悬停并且菜单处于活动状态时,这就是我喜欢的

悬停是可以的,问题是当我点击菜单后黑色地面不显示
@Jonathan,我已经解决了它,它比你给出的更简单.
这是我的答案:
$(function(){
// this will get the full URL at the address bar
var url = window.location.href;
// passes on every "a" tag
$("#sub-header a").each(function() {
// checks if its …Run Code Online (Sandbox Code Playgroud) 我是django的新手,我在djangoproject.com上完成了4部分教程
我的问题是我想在我的民意调查应用程序上进行登录身份验证.我使用装饰器@login_required并且它正常工作但在我的views.py下我只有vote()方法.
我的views.py在"polls文件夹"下
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import never_cache
from django.core.urlresolvers import reverse
from django.template import RequestContext
from polls.models import Poll, Choice
@login_required
@never_cache
def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
return render_to_response('polls/detail.html', {
'poll': p,
'error_message': "You didn't select a choice.",
}, context_instance=RequestContext(request))
else:
selected_choice.votes += 1
selected_choice.save()
return HttpResponseRedirect(reverse('poll_results', args=(p.id,)))
return HttpResponse("You're voting on poll %s." % poll_id)
Run Code Online (Sandbox Code Playgroud)
我的urls.py在"polls文件夹"下 …
我是laraval 4的新手.
我有这个问题:
SELECT a.id, active, name, email, img_location, IFNULL(b.Total, 0) AS LeadTotal, IFNULL(c.Total, 0) AS InventoryTotal
FROM users AS a
LEFT JOIN (
SELECT user_id, count(*) as Total
FROM lead_user
GROUP BY user_id
) AS b ON a.id = b.user_id
LEFT JOIN (
SELECT user_id, count(*) as Total
FROM user_inventory
GROUP BY user_id
) AS c ON a.id = c.user_id
WHERE a.is_deleted = 0
Run Code Online (Sandbox Code Playgroud)
如何将其转换为laravel查询生成器?我对如何在这种类型的查询中使用laravel连接查询构建器感到困惑.
谢谢!
回答!!
请问lakvel论坛上所有petkostas的帮助.我们得到了答案.
$users = DB::table('users AS a')
->select(array('a.*', DB::raw('IFNULL(b.Total, 0) AS LeadTotal'), DB::raw('IFNULL(c.Total, …Run Code Online (Sandbox Code Playgroud) 我有3张桌子:
users
leads
users_leads
Run Code Online (Sandbox Code Playgroud)
在users桌子上:
---------------
-- id | name --
-- 1 | doe --
-- 2 | joe --
---------------
Run Code Online (Sandbox Code Playgroud)
在leads桌子上:
----------------
-- id | type --
-- 1 | house --
-- 2 | condo --
-- 3 | house --
----------------
Run Code Online (Sandbox Code Playgroud)
在users_leads桌子上:
----------------------------
-- id | user_id | lead_id --
-- 1 | 1 | 1 --
-- 1 | 1 | 2 --
-- 1 | 2 | 3 …Run Code Online (Sandbox Code Playgroud) 你能id使用jQuery 获取html标签的属性吗?
例如:
<ul id="todo" />
Run Code Online (Sandbox Code Playgroud)
如何在id不使用的情况下获得jQuery("#todo")?
有办法吗?会attr()工作吗?
如何使用其索引反转或迭代列表?
这是一个例子
lst = [3,2,4,1,5]
Run Code Online (Sandbox Code Playgroud)
输出将是:( [3,2,4,5,1]索引3,其中1是最后的位置)
另一个例子:
lst = [1,5,4,2,3]
Run Code Online (Sandbox Code Playgroud)
输出:( [1,5,4,3,2]索引3是2到底是放在哪里)
这就像使用切片反转列表一样.
我点击管理员登录页面上的登录按钮后,我们.我收到此错误:
ValueError at /admin/
too many values to unpack
Request Method: POST
Request URL: http://localhost:8000/admin/
Django Version: 1.3.1
Exception Type: ValueError
Exception Value:
too many values to unpack
Exception Location: /home/justin/Workspace/training/django/env/local/lib/python2.7/site-packages/django/contrib/auth/models.py in check_password, line 42
Python Executable: /home/justin/Workspace/training/django/env/bin/python
Python Version: 2.7.2
Python Path:
['/home/justin/Workspace/training/django/test_project',
'/home/justin/Workspace/training/django/env/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/home/justin/Workspace/training/django/env/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/justin/Workspace/training/django/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/home/justin/Workspace/training/django/env/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/justin/Workspace/training/django/env/lib/python2.7',
'/home/justin/Workspace/training/django/env/lib/python2.7/plat-linux2',
'/home/justin/Workspace/training/django/env/lib/python2.7/lib-tk',
'/home/justin/Workspace/training/django/env/lib/python2.7/lib-old',
'/home/justin/Workspace/training/django/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/justin/Workspace/training/django/env/local/lib/python2.7/site-packages',
'/home/justin/Workspace/training/django/env/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
'/home/justin/Workspace/training/django/env/lib/python2.7/site-packages',
'/home/justin/Workspace/training/django/env/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time: Thu, 19 Apr 2012 01:36:33 -0500
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个?我不知道错误在哪里.
谢谢,贾斯汀
我需要在当前日期之前 12 个月生成一份报告。
今天是 2014 年 4 月 29 日。所以我的日期范围是 2013-04-29 到 2014-04-29。
这些是我的示例数据:
--------------------------------------
-- user_id | lead_id | date_entered --
-- 1 | 1 | 2013-12-05 --
-- 1 | 2 | 2014-03-15 --
-- 1 | 3 | 2014-04-24 --
--------------------------------------
Run Code Online (Sandbox Code Playgroud)
预期输出应该是:
--------------------------
-- month | year | total --
-- Apr | 2013 | 0 --
-- May | 2013 | 0 --
-- Jun | 2013 | 0 --
-- Jul | 2013 | 0 …Run Code Online (Sandbox Code Playgroud)