我有一个带有ForeignKey的模型A到模型B.在Django admin中,如何在打开模型B的管理页面的ForeignKey字段旁边的模型A的管理页面中添加一个链接?
我尝试设置蓝牙连接如下:
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
BluetoothSocket connection = null;
public ConnectThread(BluetoothDevice device) {
mmDevice = device;
// Get a BluetoothSocket for a connection with the
// given BluetoothDevice
try {
if(D)
Log.i(TAG, "createRfcommSocket");
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
connection = (BluetoothSocket) m.invoke(mmDevice, 1);
Utils.pause(100);
} catch (Exception e) {
Log.e(TAG, "create() failed", e);
}
if(D)
Log.i(TAG, "Bluetooth socket initialised");
mmSocket = connection;
}
public void run() …Run Code Online (Sandbox Code Playgroud) 我正在使用django rest框架,如下所述:django rest framework doc我在我的模板目录中添加了/rest_framework/api.html.
现在的结构是:
|
|\
| apps
| \
| settings.py
\
templates
\
rest_framework
\
api.html
Run Code Online (Sandbox Code Playgroud)
api.html:
{% extends "rest_framework/base.html" %}
{% block footer %}
Hello !
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
settings.py:
...
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
)),
)
Run Code Online (Sandbox Code Playgroud)
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.markup',
'django.contrib.webdesign',
...
'rest_framework',
...
)
Run Code Online (Sandbox Code Playgroud)
...
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'PAGINATE_BY': 10
} …Run Code Online (Sandbox Code Playgroud) 我的应用程序在Android 2.3.3到4.1.2下运行良好,但自Android 4.2.2和Android 4.3以来,我有一个
fatal signal 11 (SIGSEGV) at 0x00....
Run Code Online (Sandbox Code Playgroud)
当我关闭蓝牙插座时.
我通过很多论坛搜索,主要的反应是
BluetoothSocket.close();
Run Code Online (Sandbox Code Playgroud)
是从两个不同的线程同时调用,但在我的代码中并非如此.
我在A4.1.2下使用三星Galaxy Note 2(工作正常),在A4.2.2和4.3上使用Nexus 4.
提前感谢您的建议!
编辑1:这是操纵蓝牙插槽的2个线程.
首先 :
/**
* This thread runs while attempting to make an outgoing connection with a
* device. It runs straight through; the connection either succeeds or
* fails.
*/
private class ConnectThread extends Thread {
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
//private final UUID MY_UUID = java.util.UUID.randomUUID();
public ConnectThread(BluetoothDevice device) {
if(D) Log.d(TAG, "/S4B/ start connectThread "); …Run Code Online (Sandbox Code Playgroud) 我的新闻应用程序上有一个end_date字段,这是一个兼容性字段.当作者正在编辑其中一个新的并删除end_date时,我在模型中将end_date设置为None.
我的问题是该字段然后在下次编辑时显示值"无"而不是空白.
这是我的领域:
models.py
end_date = models.DateTimeField(null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
forms.py
end_date = forms.CharField(label='', required=False, widget=forms.DateTimeInput(attrs={'class': 'form-control', 'format': 'DD, d MM yy', 'placeholder': _('End date')}))
Run Code Online (Sandbox Code Playgroud)
和我认为的分配:
views.py
if news_form.cleaned_data['end_date'] == '' :
edited_new.end_date = None
edited_new.save()
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我的模板:
news.html
<form action="#" method="post" role="form" id="news-form">{% csrf_token %}
{{ news_form.media }}
<div class="col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-12 col-md-6">
<h2 class="panel-title">{% trans "Add or edit news" %}</h2>
</div>
<div class="col-xs-12 col-md-6">
<div class="pull-right">
<a href="#" class="btn btn-secondary cancel"><span class="glyphicon glyphicon-floppy-remove"></span> …Run Code Online (Sandbox Code Playgroud) 在我的 Android 应用程序中,我正在寻找特定的蓝牙设备。当我找到一个蓝牙设备时,我会检查它是否是我正在寻找的设备,如果是,我会调用 cancelDiscovery();
我的问题是:如果我取消发现,我是否还会收到 ACTION_DISCOVERY_FINISHED 广播?
谢谢 !
服务器应答Access-Control-Allow-Origin为生产设置的值.当请求来自我的开发服务器时,有没有办法允许?例如,是否有Django设置禁用跨源检查DEBUG=True?
我无法修改Access-Control-Allow-Origin.请求是使用jquery ajax函数完成的.
编辑:
我已经安装了https://github.com/ottoyiu/django-cors-headers用pip install django-cors-headers,添加下面的我settings.py
if DEBUG:
INSTALLED_APPS += ('corsheaders', )
CORS_ORIGIN_ALLOW_ALL = DEBUG
Run Code Online (Sandbox Code Playgroud)
并把中间件:
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
...
}
Run Code Online (Sandbox Code Playgroud)
但我仍然得到错误:
阻止跨源请求:同源策略禁止在_request_url_读取远程资源.(原因:缺少CORS标题'Access-Control-Allow-Origin').
如果我检查响应头,我没有看到任何Access-Control-Allow-Origin参数.