我在django的管理中尝试了很多查找当前用户ID的方法.我试过通过SessionKey和request.user(HTTPRequest)拉取用户ID无济于事.我最近的化身是:
def save(self, request, obj, form, change):
if getattr(obj, 'submitter', None) is None:
obj.submitter = request.user
obj.save()
super(AppAdmin, self).save()
Run Code Online (Sandbox Code Playgroud)
在admin.py和
submitter = models.ForeignKey(User, null=True, blank=True, related_name="submitter")
Run Code Online (Sandbox Code Playgroud)
在models.py中.我在堆栈溢出的其他地方发现了这个,但它似乎不起作用.任何帮助表示赞赏.
谢谢!
我正在使用:`private void get_stocks_data(){byte [] result; byte [] buffer = new byte [4096];
WebRequest wr = WebRequest.Create("http://www.tase.co.il/TASE/Pages/ExcelExport.aspx?sn=he-IL_ds&enumTblType=AllSecurities&Columns=he-IL_Columns&Titles=he-IL_Titles&TblId=0&ExportType=1");
using (WebResponse response = wr.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
using (MemoryStream memoryStream = new MemoryStream())
{
int count = 0;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while (count != 0);
result = memoryStream.ToArray();
write_data_to_excel(result);
}
}
}`
Run Code Online (Sandbox Code Playgroud)
下载excel文件,
并且这种方法可以在我的计算机上填充文件:
private void write_data_to_excel(byte[] input)
{
StreamWriter str = new StreamWriter("stockdata.xls");
for (int i = 0; input.Length > …Run Code Online (Sandbox Code Playgroud) 我正在尝试在html5上传文件中进行一些测试,这里是简单的html代码:
var fileInput=document.getElementById("the-file")
fileInput.addEventListener('change',function(e){
var file=e.target.files[0]
var xhr=new XMLHttpRequest()
xhr.open('post','upload/handlecode',true)
xhr.send(file)
}
我
python -m SimpleHTTPServer
用来测试这一节的问题是我不知道如何编写handlecode文件来处理http请求,
该handlecode文件只保存文件上传floder,没有更复杂的任务
虽然我不知道以这种方式测试是否正确
有人可以提供一些提示或给我正确的测试方法,非常感谢你们!
好的,我有两个网站,我们称之为A和B.网站A有一个带文件附件的多部分表格; 站点B有一个类似的形式(我将不会使用)和它提交的处理页面.由于浏览器原始策略,我正在向站点B添加一个"代理页面",我可以从站点A发布.然后,代理页面需要将数据"转发"到处理页面并获得响应,我将用于生成JSONP以发送回站点A.
我通常使用会话或只是生成并自动提交代理页面上的表单,但我不知道如何执行此操作,因为它涉及文件输入标记.我想我可以使用这样的东西:http://www.php.net/manual/en/function.httprequest-send.php
有任何想法吗?
我$.getJSON()在localhost上遇到了很奇怪的问题.我的测试代码如下:
$(document).ready(function(){
var url = "http://script.mydomain.com/location/newid"
var url2 = "http://localhost/cms/location/newid"
$.getJSON(url2, function(id) {
alert(id);
});
});
Run Code Online (Sandbox Code Playgroud)
对于url2,它工作得很完美,但是对于url它不起作用.任何人都可以提供一些解决这个问题的提示吗?如果有人想知道,这些网址会返回json(例如:"34").
编辑[求助]:
如果将来有人会$.getJSON记得你不能称之为"外星人"域名.
当我在script.mydomain.com域下执行开销脚本时一切正常!
我有一个小的Android应用程序,向服务器发出一些POST请求,问题是我希望我的应用程序能够在请求失败时,在检查设备上的网络可用性后重试Post一段时间.怎么做到这一点?是否有必要实现一个服务和一个数据库来保存我发送的数据?我已经阅读了一些关于alarmmanager的内容,但我不知道如何通过我的活动实现这一点.
我正在尝试使用谷歌API v2在我的应用程序中设置路线方向,但我收到此错误,我找不到导致问题的原因
D/Exception while reading url? java.io.FileNotFoundException: https://maps.googleapis.com/maps/api/directions/json?waypoints=optimize:true|-23.3246,-51.1489|-23.3206,-51.1459|-23.2975,-51.2007&sensor=false
Run Code Online (Sandbox Code Playgroud)
当我在Chrome上复制并粘贴该链接时,我得到以下信息:
"error_message":"无效请求.缺少'origin'参数.",
这是我的地图类:
public class MapaViagem extends FragmentActivity {
private GoogleMap googleMap;
private String IdViagem;
private List<EnderecoModel> mEnderecoModel = new ArrayList<EnderecoModel>();
private ArrayList<LatLng> coordList = new ArrayList<LatLng>();
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
setContentView(R.layout.maps);
// Loading map
initilizeMap();
// Changing map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
// googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
// googleMap.setMapType(GoogleMap.MAP_TYPE_NONE);
// Showing / hiding your current location
googleMap.setMyLocationEnabled(true);
// Enable / Disable zooming controls
googleMap.getUiSettings().setZoomControlsEnabled(true); …Run Code Online (Sandbox Code Playgroud) 我试图User-Agent在我的HTTP请求中添加一个头(在Ruby中),但不确定用户代理字符串的格式.这是它在Perl中的定义方式:
use LWP::UserAgent;
my $ua = new LWP::UserAgent(keep_alive=>1);
$ua->credentials($netloc, '', "$user", "$pwd");
Run Code Online (Sandbox Code Playgroud)
如果我尝试print $ua;,我会得到一个每次都改变的哈希值.我相信在Ruby中我应该将凭证嵌入到单个字符串中.我怎么知道如何格式化这个字符串?或者,如何成功打印$uaPerl中的内容?
Ruby代码:
http = Net::HTTP.new("your.site.com", 80)
req = Net::HTTP::Get.new("/path/to/the/page.html", {'User-Agent' => 'your_agent_here'})
response = http.request(req)
Nodejs服务器端实现:如何使用https://www.npmjs.com/package/request与https://www.npmjs.com/package/rx一起向https://www.reddit.com/发出GET请求r/javascript.json?
目标:无论何时我正在使用的网站api url都有数据更改,我都会尝试实现持续流式处理.
我正试图弄清楚如何使用Javascript来发出DELETE请求.我有一个用Java Spring编写的服务,其中我正在处理的url的控制器method = RequestMethod.DELETE.我的网址是,比如说http://192.168.50.51/my-service/deleteLocation/{value1}/{value2}/{value3}.在我的JavaScript中,我有一个像这样的AJAX函数:
ajaxFunction : function(url, callback, httpMethod) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var jsonParse = JSON.parse(xhttp.responseText);
callback(jsonParse);
}
}
xhttp.open(httpMethod, url, true);
xhttp.send();
}
Run Code Online (Sandbox Code Playgroud)
当我想使用DELETEurl时,我有一个事件处理程序附加到运行此方法的按钮:
deleteConfirm : function() {
var valuel = this.value1;
var value2 = document.getElementById('element-id').getAttribute('data-element');
var value3 = document.getElementById('element-id').getAttribute('data-element2');
var url = 'http://192.168.50.51/my-service/deleteInfo/' + value1 + '/' + value2 + '/' + value3;
var httpMethod = …Run Code Online (Sandbox Code Playgroud) httprequest ×10
android ×2
javascript ×2
python ×2
.net ×1
admin ×1
ajax ×1
alarmmanager ×1
c# ×1
django ×1
getjson ×1
google-maps ×1
html5 ×1
http-delete ×1
httpresponse ×1
jquery ×1
json ×1
node.js ×1
perl ×1
php ×1
polyline ×1
rest ×1
ruby ×1
rxjs ×1
service ×1
testing ×1
user-agent ×1
webforms ×1