在我的代码中,我有:
class A:
def a():
......
def b():
a()
......
b()
Run Code Online (Sandbox Code Playgroud)
然后编译器会说"NameError:未定义全局名称a()".如果我从A类中提取所有东西,那就不会有问题,但是如何在A类中定义方法呢?非常感谢你.
我有一个问题,Django可以做多线程的工作吗?
这就是我想要做的:点击网页上的一个按钮,然后在model.py中有一些功能开始运行,例如,从互联网抓取一些数据,完成后,它会返回给用户结果.
我想我必须打开一个新的线程来执行model.py中的函数,有人能告诉我怎么做吗?非常感谢你.
我有一个关于如何从模板HTML按钮调用视图函数的问题?像一个onclick功能?这是模板:
<input id="submit" type="button" onclick="xxx" method="post" value="Click" />
Run Code Online (Sandbox Code Playgroud)
而views.py是:
def request_page(request):
...do something...
return render_to_response("/directory.html", {})
Run Code Online (Sandbox Code Playgroud)
非常感谢你.
我有一个类GroupAdminForm,用于扩展Django中的组管理页面.有两个字段,selected_to_change和print_name.我正在设计的是在"selected_to_change"中选择一列并在"print_name"中输入一个字符名称,以便进行如下查询:
UPDATE "annotation"
SET print_name= "value of print_name"
WHERE id = "value of selected_to_change";
Run Code Online (Sandbox Code Playgroud)
这是GroupAdminForm:
class GroupAdminForm(forms.ModelForm):
users = forms.ModelMultipleChoiceField(queryset=User.objects.all(),
widget=FilteredSelectMultiple('Users', False),
required=False)
select_to_change = forms.ModelChoiceField(queryset=Annotation.objects.all(), required=False)
print_name = forms.CharField(required=False)
class Meta:
model = Group
def __init__(self, *args, **kwargs):
instance = kwargs.get('instance', None)
if instance is not None:
initial = kwargs.get('initial', {})
initial['users'] = instance.user_set.all()
initial['locations'] = instance.c_locations.all()
kwargs['initial'] = initial
super(GroupAdminForm, self).__init__(*args, **kwargs)
def save(self, commit=True):
group = super(GroupAdminForm, self).save(commit=commit)
if commit:
group.user_set = self.cleaned_data['users']
else:
old_save_m2m = self.save_m2m …
Run Code Online (Sandbox Code Playgroud) 我已经在 Apache 上部署了 django 站点,并且在我的开发机器上没有出现问题,所以我想打印一些变量来看看发生了什么。
我尝试使用 python 日志记录模块,我这样做了:
import os, logging
FILE = os.getcwd()
logging.basicConfig(filename=os.path.join(FILE,'log.txt'),level=logging.DEBUG)
logging.debug('Write')
Run Code Online (Sandbox Code Playgroud)
在我的开发机器上,我的 django 项目的根目录中可能会显示一个 log.txt。但是,当我执行相同的操作时,我的服务器上的相应目录中没有显示 log.txt 文件。
有谁知道如何调试它?谢谢!
我想知道如何在 views.py 中获取当前用户 ID?此外,如何获取当前用户的组 ID?我是否必须使用用户 id 直接查询数据库?非常感谢。
谁能告诉我如何从GeoJsonDataSource获取位置数据?这是我在做的事情:
entity1 = Cesium.GeoJsonDataSource.fromUrl('../../SampleData/markersdata.geojson');
var array1 = entity1.entities.entities; //According to document, this should an array of entity instances, but it only returns an empty array.
console.log(array1);
// []
//If I do this:
var assocArray = entity1.entities._entities; //This returns an associative array
var markersArr = assocArray.values; //I expect this returns an array of values, but it still returns empty array.
console.log(markersArr);
// []
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
所有,我正在用OpenMP编译一个C程序.这是我第一次使用makefile.当激活"make"时,gcc报告错误make:*没有规则使目标omp.h', needed by
smooth.o'.停止.但是omp.h位于/usr/lib/gcc/i686-linux-gnu/4.6/include/omp.h中,我想知道如何修复它.谁能帮助我?谢谢.
CC=gcc
CFLAGS = -fopenmp
all: smooth
smooth: smooth.o ompsooth.o
$(CC) $(CFLAGS) -o smooth smooth.o ompsmooth.o
ompsmooth.o: ompsmooth.c assert.h stdio.h stdlib.h omp.h ompsmooth.h
gcc $(CFLAGS) ompsmooth.c
smooth.o: smooth.c ompsmooth.h omp.h stdio.h stdlib.h string.h sys/types.h sys/stat.h fcntl.h
gcc $(CFLAGS) smooth.c
clean:
rm *.o
rm smooth
Run Code Online (Sandbox Code Playgroud) django ×5
python ×3
django-admin ×2
apache ×1
c ×1
cesium ×1
django-forms ×1
django-views ×1
gcc ×1
javascript ×1
makefile ×1
nameerror ×1
openmp ×1
templates ×1
view ×1