我试图通过将我的 html 文档使用的 SVG 文件移动到对象标记中来使阅读体验更愉快。
SVG 的部分目的是使其可点击,从而改变其颜色。这是通过 JavaScript 完成的。
只要 SVG 位于父 html 中,一切就可以正常工作,但一旦我尝试使用对象标签,JavaScript getElementById 就会失败(console.log(svg_rectangle) 返回 null)。我假设 DOM 不再知道 SVG 元素一旦移动到对象标签中,所以它与范围有关?
谷歌搜索这个不太走运,我不是 DOM 专家,所以也许我没有使用正确的关键字。
我通过 Django 运行它,因此是 {{ STATIC_URL }}。
超文本标记语言
<html>
<body>
<object id="svg1" data="{{ STATIC_URL }}svg/test.svg" type="image/svg+xml"></object>
<!--
<svg
id="svg_square"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
height="256"
width="256"
version="1.1"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<g class="region">
<rect id="rect_front" transform="scale(1,-1)" height="64" width="64" y="-128" x="64" onclick="parent.testFunction(this.id)"/>
</g>
</svg>
-->
<script src="{{ STATIC_URL }}archive_140520/handle_svg.js" type="text/javascript"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JavaScript
function testFunction(id){
console.log(id)
var svg_rectangle = document.getElementById(id);
console.log(svg_rectangle) …Run Code Online (Sandbox Code Playgroud) 我一直在使用 Geo-Django GeoJSON 序列化程序,以便我可以从 PostGIS 数据库中检索一些对象并将它们显示在 OpenLayers 地图上。
我通过以下方式获取要显示的对象:
gqs = self.model.objects.filter(point__distance_lte=(pnt, long(dist)))
type(gqs)
<class 'django.contrib.gis.db.models.query.GeoQuerySet'>
Run Code Online (Sandbox Code Playgroud)
并且地理对象包括预期的所有模型字段:
self.model._meta.get_fields()
(<django.db.models.fields.AutoField: id>,
<django.db.models.fields.CharField: name>,
<django.db.models.fields.SlugField: name_slug>,
<django.db.models.fields.CharField: contact>,
<django.db.models.fields.CharField: address>,
<django.db.models.fields.CharField: postcode>,
<django.db.models.fields.EmailField: email>,
<django.db.models.fields.CharField: fax>,
<django.db.models.fields.CharField: tel>,
<django.db.models.fields.CharField: tel1>,
<django.db.models.fields.CharField: tel_fax>,
<django.db.models.fields.URLField: url>,
<django.db.models.fields.CharField: wardlabel>,
<django.db.models.fields.DecimalField: lon>,
<django.db.models.fields.DecimalField: lat>,
<django.db.models.fields.IntegerField: easting>,
<django.db.models.fields.IntegerField: northing>,
<django.db.models.fields.DateField: first_entered>,
<django.db.models.fields.DateField: updated>,
<django.contrib.gis.db.models.fields.PointField: point>)
Run Code Online (Sandbox Code Playgroud)
包括id值...
(Pdb) gqs[0].id
5
Run Code Online (Sandbox Code Playgroud)
然后我以最简单的方式将 GeoQuerySet 传递给 GeoJSON 序列化程序:
gqs_serialized = serialize('geojson', gqs)
Run Code Online (Sandbox Code Playgroud)
并获得输出:
gqs_serialized
u'{"type": "FeatureCollection",
"crs": {
"type": "name", …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Centos 7操作系统连接到Moto3G Android手机(运行Android v6 - marshmallow)
已安装libmtp
Package libmtp-1.1.6-5.el7.x86_64 already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)
互联网上的大多数搜索建议使用mtp-detect但在我的情况下:
bash: mtp-detect: command not found
Run Code Online (Sandbox Code Playgroud)
我可以看到使用dmesg的手机
[ 6446.771306] usb 1-1.2: Product: XT1039
[ 6446.771309] usb 1-1.2: Manufacturer: motorola
Run Code Online (Sandbox Code Playgroud)
我安装了jmtpfs(使用yum),它给了我以下内容
jmtpfs
No mtp devices found.
Run Code Online (Sandbox Code Playgroud)
我尝试使用GO 安装go-mtpfs,但得到以下内容
$ ./gopath/bin/go-mtpfs bob &
[1] 21633
$ 2017/05/03 13:06:18 detect failed: no MTP devices found
[1]+ Exit 1 ./gopath/bin/go-mtpfs bob
Run Code Online (Sandbox Code Playgroud)
如果有人对此进展有任何意见或建议,我将不胜感激.
使用通用的基于类的CreateView我试图通过ClearableFileInput小部件上传图像,这是由inlineformset_factory使用的默认小部件,但这是失败的.
form.save()在我的视图中运行得很好,它似乎是失败的specimage_form.save().如果我在提交过程中打印self.request.FILES,看起来好像所选文件在内存中 - 但是在SpecImage save()函数中粘贴一个print语句,很明显这个函数永远不会被调用.
可以使用内联管理站点上传图像,在这种情况下我会看到print语句.
这是我的代码 - 感谢任何建议或指导.提前致谢..
models.py
class Spec(models.Model):
car = models.ForeignKey('vehicles_dvla_listpoint.AutoLookup')
owner = models.ForeignKey(User)
uploaded = models.DateField(default=date.today, editable=False)
def get_absolute_url(self):
return reverse('car_create')
def __unicode__(self):
return "{0}".format(self.car)
class SpecImage(models.Model):
def orig_car_id_folder(instance, filename):
return 'uploads/images/orig/{0}/{1}'.format(instance.car_id, filename)
def thumb_car_id_folder(instance, filename):
return 'uploads/images/thumb/{0}/{1}'.format(instance.car_id, filename)
car = models.ForeignKey(Spec)
orig_image = models.ImageField(
upload_to=orig_car_id_folder,
verbose_name='Upload Image',
)
thumbnail = models.ImageField(
upload_to=thumb_car_id_folder,
null=True,
blank=True,
)
def save(self, force_update=False, force_insert=False):
print "here ...." # << Don't see this where submitting outside of the admin
import …Run Code Online (Sandbox Code Playgroud)