我正在尝试获取一个JSON对象:
{
"username": "clelio",
"name": "Clelio de Paula",
}
Run Code Online (Sandbox Code Playgroud)
并将其转换为:
class User(models.Model):
name = models.CharField(max_length=30)
username = models.CharField(max_length=20)
def jsonToClass(s):
aux = json.dumps(s, self)
self.name = aux['name']
self.id = aux['id']
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用simplejson
一个叫做的方法jsonToClass()
:
>>> import simplejson as json
>>> u1 = User()
>>> u1.jsonToClass(face)
>>> u1.save()
Run Code Online (Sandbox Code Playgroud)
这不起作用.做我想要的最简单方法是什么?
当我尝试在webfactional上运行我的服务器上的webapp时,我在2小时内遇到了关于STATIC_URL和STATIC_ROOT的问题.
当我加载网页时,所有请求都能正常运行,除非{{STATIC_URL}}的任何链接正在运行或加载.
因此,firebug上出现的常见错误是:
GET http://mydomain/static/extras/h5bp/js/libs/modernizr-2.5.3.min.js 500 (Internal Server Error)
Run Code Online (Sandbox Code Playgroud)
我的设置是:
urls.py我什么也没做,而且静态文件也没什么.
settings.py DEBUG = False
STATIC_ROOT = '/home/mydomain/webapps/static_app/'
STATIC_URL = 'http://mydomain/static/'
STATICFILES_DIRS = ()
Run Code Online (Sandbox Code Playgroud)
views.py视图示例
@csrf_exempt
def IndexView(request):
try:
request.user.is_authenticated()
except AttributeError:
return render_to_response('index.html',
{'request': request,},
context_instance=RequestContext(request))
return render_to_response('index.html',
{'request': request, 'profile' : request.user},
context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
index.html找不到代码的一部分
<script src="{{ STATIC_URL }}extras/h5bp/js/libs/modernizr-2.5.3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
好吧,我遵循以下所有要点:https: //docs.djangoproject.com/en/1.4/howto/static-files/ 和另一个:http: //docs.webfaction.com/software/django/getting- started.html
我正在使用正确安装的应用程序,中间件,template_contexts.
如果我错过了什么,请帮助我搞清楚.
提前致谢!
- 编辑
我不得不说,如果我只是更改DEBUG = True将正常工作.
因为在urls.py上我有这段代码:
if settings.DEBUG:
# static files (images, css, javascript, etc.)
urlpatterns += patterns('', …
Run Code Online (Sandbox Code Playgroud) i'm making a crawler to get text html inside, i'm using beautifulsoup.
when I open the url using urllib2, this library converts automatically the html that was using portuguese accents like " ã ó é õ " in another characters like these "a³ a¡ a´a§"
what I want is just get the words without accents
contrã¡rio -> contrario
I tried to use this algoritm, bu this one just works when the text uses words like these "olá coração contrário"
def …
Run Code Online (Sandbox Code Playgroud) 我有一个json文件,其元素如下:
[{
"name": "Manuel Jose",
"ttags": ["vivant", "designer", "artista", "empreendedor"]
}]
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此结构获取节点和边缘以完成如下图形:
(图表取自d3.js文档)
我name
和ttags
json文件中的两个都指节点,ttags
实际上是节点和另一个节点之间的链接.
但是,我无法理解如何使用此库d3及以上的json文件创建此图.
d3.json("/data/tedxufrj.json", function(classes) {
var nodes = cluster.nodes(package.root(classes)),
links = package.imports(nodes);
vis.selectAll("path.link")
.data(splines = bundle(links))
.enter().append("path")
.attr("class", "link")
.attr("d", line);
vis.selectAll("g.node")
.data(nodes.filter(function(n) { return !n.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; })
.append("text")
.attr("dx", function(d) { return d.x < 180 ? 8 : -8; }) …
Run Code Online (Sandbox Code Playgroud) 我在OpenFrameworks图片中遇到此错误.但似乎是一个简单的C++问题.
ofVec2f does not refer to a value
Run Code Online (Sandbox Code Playgroud)
当然我有指针问题,但我不明白为什么.我试图改变& - >*
canvas4.cpp
void Canvas4::createStuff() {
ballCollection.clear();
for (int i=0; i<num; i++) {
ofVec2f org;
org.set(ofRandom(edge, ofGetWidth()-edge), ofRandom(edge, ofGetHeight()-edge));
float radius = ofRandom(50, 150);
ofVec2f loc;
loc.set(org.x+radius, org.y);
float offSet = ofRandom(TWO_PI);
int dir = 1;
float r = ofRandom(1);
if (r>.5) dir =-1;
myBall = new Ball(org, loc, radius, dir, offSet);
ballCollection.push_back(* myBall);
}
//
Run Code Online (Sandbox Code Playgroud)
这是Ball类的构造函数;
Ball::Ball(ofVec2f &_org, ofVec2f &_loc, float _radius, int _dir, float _offSet) {
// **** error …
Run Code Online (Sandbox Code Playgroud) 我遇到一个简单的问题.
a = {
"apiVersion": "2.1",
"data": {
"startIndex": 1,
"items": [{
"id": "YVA3UoZM0zU",
"title": "Trailer - Lisbela eo Prisioneiro"
}]
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何获取信息ID.这是一个字符串.所以,我试图做到这一点
import simplejson as json
>>> type(js)
<type 'dict'>
js = json.loads(a)
print js['data'{'items'[{'id'}]}]
>>> syntax error
Run Code Online (Sandbox Code Playgroud)
这个语法无效,我怎么能得到这个信息?这应该很容易.我在哪里做错了?
我使用django-ajax-select为模型区域上的字段创建了一个查找通道,以便在我创建或编辑UserProfile时在我的ModelForm上选择字段.
class FormRegisterProfile(forms.ModelForm):
class Meta:
model = UserProfile
exclude = ('user')
interests = make_ajax_field(UserProfile,'interests','areas2',help_text=True)
expertise = make_ajax_field(UserProfile,'expertise','areas2',help_text=True)
Run Code Online (Sandbox Code Playgroud)
发生的事情是,当我使用没有管理员权限的用户登录时,我会在服务器上获得此行
[16/Aug/2012 14:56:12] "GET /profile/ajax_lookup/areas2?term=g HTTP/1.1" 403 22
Run Code Online (Sandbox Code Playgroud)
我的url.py
(r'^admin/lookups/', include(ajax_select_urls)),
(r'^profile/', include(ajax_select_urls)),
url(r'^profile/edit/$', 'mycu.views.EditUserProfile', {}, 'register.html'),
url(r'^admin/', include(admin.site.urls)),
Run Code Online (Sandbox Code Playgroud)
我的查找频道:
AJAX_LOOKUP_CHANNELS = {
'areas' : {'model':'mycu.areas', 'search_field':'type'},
'areas2' : ('mycu.lookups', 'AreasLookup'),
Run Code Online (Sandbox Code Playgroud)
我的lookups.py
class AreasLookup(LookupChannel):
model = Areas
def get_query(self,q,request):
return Areas.objects.filter(Q(type__icontains=q)).order_by('type')
def get_result(self,obj):
u""" result is the simple text that is the completion of what the person typed """
return obj.type
def format_match(self,obj): …
Run Code Online (Sandbox Code Playgroud) 有哪些逻辑选择:
{% if request.user.is_active %}
Run Code Online (Sandbox Code Playgroud)
如果视图没有render_to_response
带字典返回request
,则模板无法正常工作.
所以,欢迎任何想法.
//编辑
我的动机是:当您处理已安装应用程序的视图时,您没有机会修改它们.
python authentication django django-templates render-to-response
解决这个简单问题的好习惯是什么?
def __unicode__(self):
return unicode(self.typePlace + " " + self.name)
Run Code Online (Sandbox Code Playgroud)
TypeError:+的不支持的操作数类型:'TipoLugar'和'str'
这部分代码代表我网页的索引,例如:127.0.0.1:8000/
def IndexView(request):
try:
profile = request.user.get_profile()
except User.DoesNotExist:
return render_to_response('index.html',
{'request': request,},
context_instance=RequestContext(request))
return render_to_response('index.html',
{'request': request, 'profile' : profile},
context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
为什么我在调试时仍然收到此错误?
AttributeError at / 'AnonymousUser' 对象没有属性 'get_profile'
提前致谢
django ×5
python ×5
json ×3
string ×2
unicode ×2
c++ ×1
d3.js ×1
deployment ×1
dictionary ×1
javascript ×1
lookup ×1
object ×1
pointers ×1
svg ×1
try-catch ×1
url ×1
urllib ×1
utf-8 ×1
webfaction ×1