我有以下代码,这应该是使用google api javascript客户端的简单示例,并且只显示硬编码缩短URL的长格式URL:
<script>
function appendResults(text) {
var results = document.getElementById('results');
results.appendChild(document.createElement('P'));
results.appendChild(document.createTextNode(text));
}
function makeRequest() {
console.log('Inside makeRequest');
var request = gapi.client.urlshortener.url.get({
'shortUrl': 'http://goo.gl/fbsS'
});
request.execute(function(response) {
appendResults(response.longUrl);
});
}
function load() {
gapi.client.setApiKey('API_KEY');
console.log('After attempting to set API key');
gapi.client.load('urlshortener', 'v1', makeRequest);
console.log('After attempting to load urlshortener');
}
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
Run Code Online (Sandbox Code Playgroud)
除了使用实际的API密钥而不是文本"API_KEY".
控制台输出简单:
尝试设置API密钥后
尝试加载urlshortener后
但我从来没有看到'inside makeRequest',它位于makeRequest函数内部,这是调用gapi.client.load的回调函数,让我相信函数无法正常工作(或者无法完成).
任何人都可以阐明为什么会这样,以及如何解决它?
提前致谢.
javascript google-api url-shortener google-url-shortener google-api-client
我正在尝试从特定客户端删除报告,所以目前在我的url.py传递客户端ID和报告ID,希望从客户端X删除报告Y.我本可以使用def ReportScheduleDeleteView(request):,但希望使用类 - 基于DeleteView.
我看了一下,this example但无法与我的代码混合.
所以这是我的代码.
urls.py
url(r'^jsclient/(?P<pk>\d+)/report/(?P<r_pk>\d+)/delete/$', ReportScheduleDeleteView.as_view(), name="report-delete"),
Run Code Online (Sandbox Code Playgroud)
models.py -
class JSClient(models.Model):
name = models.CharField(max_length=255, unique=True)
clientAccount = models.CharField(max_length=255)
....
class ReportSchedule(models.Model):
client = models.ForeignKey(JSClient)
schedRepName = models.CharField(max_length=255)
reportType = models.CharField(max_length=255, choices=REPORT_TYPE)
....
Run Code Online (Sandbox Code Playgroud)
views.py:
class ReportScheduleDeleteView(DeleteView):
model = ReportSchedule
template_name = "report/report_confirm_delete.html"
success_url = lazy(reverse, str)('jsclient-list')
Run Code Online (Sandbox Code Playgroud)
我确信必须有一种方法可以使用基于类的DeleteView来做到这一点,任何帮助都是值得赞赏的.
我处于这样一种情况,我需要制作自定义身份验证和自定义中间件来验证和授权用户.我必须在POST请求中设置用户名密码params,或者是否设置了cookie用于基于令牌的身份验证.现在,我知道python中不允许函数重载,我怎么能实现它.我将下面的代码放在自定义身份验证和自定义中间件上.
自定义中间件:
from django.contrib.auth import authenticate
class AuthMiddleWare(object):
def process_request(self, request):
if request.path != '/favicon.ico':
print "inside process_request " + request.path
if request.method == 'POST' and request.POST.has_key('username' ) and request.POST.has_key('password'):
authenticate(username = request.POST.get('username'),password = request.POST.get('password'))
if 'SPRING_SECURITY_REMEMBER_ME_COOKIE' in request.COOKIES:
authenticate(token = request.COOKIES.get('SPRING_SECURITY_REMEMBER_ME_COOKIE'))
return None
Run Code Online (Sandbox Code Playgroud)
和自定义身份验证后端:
from core.api import NcpAPI
class CustomNCPAuthBackend(object):
"""
This is custom authentication backend.
Authenticate against the webservices call.
The method below would override authenticate() of django.contrib.auth
"""
def authenticate(self, username = None, password = None):
print …Run Code Online (Sandbox Code Playgroud) python django django-middleware django-authentication python-2.7
我正在尝试使用angular-nvd3扩展来自定义饼图的颜色.
这就是我在这里抓到的东西.正如您所看到的那样,图例的颜色正在定制,但图表却没有.
我需要在数据对象中传递颜色.你有什么想法我可以解决它吗?
这是场景.我有一张表,其中包含所有联系方式.另一个包含所有类别列表的表.第三个表是一个关联表,它具有第一个表的ID和第二个表的ID.
这就是我的关联表的样子
contactdid -2 | categoryid -1
contactdid -2 | categoryid -2
contactdid -2 | categoryid -3
contactdid -3 | categoryid -1
contactdid -3 | categoryid -3
这是我下面的SQL代码(使用SQLyog生成,i包含where子句).
SELECT
press_contacts.email
FROM
contacts_category
INNER JOIN press_category
ON (contacts_category.categoryid = press_category.id)
INNER JOIN press_contacts
ON (contacts_category.contactdid = press_contacts.id)
WHERE contacts_category.categoryid = 1 AND contacts_category.categoryid = 2 ;
Run Code Online (Sandbox Code Playgroud)
我没有AND contacts_category.categoryid = 2在代码中插入时得到输出.
任何想法如何解决这个问题.我显然有数据.在此先感谢您的帮助.
django ×2
javascript ×2
angularjs ×1
django-views ×1
google-api ×1
mysql ×1
nvd3.js ×1
python ×1
python-2.7 ×1
sql ×1