对Django来说很新,所以我很抱歉,因为我确信这有一个简单的答案.
我有一个PHP背景,所以我猜我正试图强制我习惯的结构,而不是Django中的原生结构.
这是我的项目urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('pm.urls', namespace='pm')),
)
Run Code Online (Sandbox Code Playgroud)
这是我的应用程序urls.py
from django.conf.urls import patterns, url
from pm import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^label/add/$', views.add_label, name='label_add'),
)
Run Code Online (Sandbox Code Playgroud)
我正在对/ label/add /做一个AJAX Post请求,但它回来时出现500错误.
这是views.py
:
from django.shortcuts import render
from pm.models import Label
import json
# Create your views here.
def index(request):
labels_list = Label.objects.order_by('name')
return render(request, 'pm/index.html', {
'labels' : …
Run Code Online (Sandbox Code Playgroud) 我能够毫无问题地使用旧版本的Twitter Typeahead,我对新版本的知识肯定是有限的,我肯定对为什么会出现重复条目感到困惑.
这是我的Javascript:
// Sources
var sources = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '/sources/prefetch/',
remote: '/sources/prefetch/'
});
sources.initialize();
$('#a_sources_list').typeahead(null, {
name: 'sources',
displayKey: 'name',
source: sources.ttAdapter()
})
Run Code Online (Sandbox Code Playgroud)
/ sources/prefetch / returns:
[{"id":"1","name":"Google"},{"id":"3","name":"Yahoo"}]
Run Code Online (Sandbox Code Playgroud)
以下是正在发生的事情的屏幕截图:
这是我的设置。
Javascript/jQuery:
$('#list').dataTable({
paging: false,
serverSide: true,
ajax: {
url: "/search/",
data: function (d) {
return $.extend({}, d, {
lid: Label.selectedId
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
HTML
<table id="list" class="table table-striped" width="100%">
<thead>
<tr>
<th>Title</th>
<th>First Name</th>
<th>Last Name</th>
<th>URL</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
JSON 响应
{"data": [["Test", "", "", ""]], "recordsTotal": 1, "draw": 1, "recordsFiltered": 1}
Run Code Online (Sandbox Code Playgroud)
通过这样做手动调用它:
$('#list').DataTable().ajax.reload();
Run Code Online (Sandbox Code Playgroud)
但表不会改变。我已经用 DataTables 1.9 做了很多次了,没有任何问题——有什么想法吗?
更新
我发现如果我关掉serverSide
它,它会起作用。
我对bash和其他一些人都很陌生,而且我已经在网上找了很多解决方案来做我需要的东西,但我正在寻找最佳方式.
有些人使用sed
,有些人使用find
.
我试图找到并替换目录中的所有文件(递归).
关于如何做或在哪里看的任何建议?
编辑
我知道,现在,这并不直接与SSH有关,但它是我寻找答案的地方,我觉得其他人也可能在同一个地方看.
让我设置场景:
我有一个"Item"类,它有不同的食物(如胡萝卜,苹果等).这链接到"项目"表.一切都很好.
在我迁移的旧框架中,我还有一个"Complete Protein"类,它在构造函数中需要一个Item对象.然后,这个"CompleteProtein"对象将能够执行复杂的查询和方法,并包含有关"完整蛋白质"的一般信息.
这适合Laravel?它似乎不是一个雄辩的模型,因为它不直接与数据库中的任何表相关,但它确实进行数据库查询.它确实有依赖注入(Item),以及类中的复杂方法和常量.
我应该以某种方式使这些适合"Item"类吗?我觉得那会很混乱.
奇怪的是 - 所有这一切都在5.2工作,但我不知道有什么可以改变才能实现这一点.下面是错误和插入的数组.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'gender' cannot be null (SQL: insert into `tenants` (`name`, `phone`, `email`, `description`, `gender`, `date_birth`, `background_check_status`, `picture_url`, `work`, `position`, `country`, `location`, `hobbies`, `updated_at`, `created_at`) values (Amadeo Levy Luna, 18065496549, amadeo.luna@ttu.edu, , , 2017-05-08 20:29:50, 0, , , , , , , 2017-05-08 20:29:50, 2017-05-08 20:29:50)) ?"
array:13 [?
"_token" => "9HeacY4KskT5vpLPGCUTkzVxRcpcKMNjdob79aLs"
"name" => "Amadeo Levy Luna"
"phone" => "18065496549"
"email" => "amadeo.luna@ttu.edu"
"description" => null
"gender" => null
"background_check_status" => "0"
"picture_url" …
Run Code Online (Sandbox Code Playgroud) jquery ×2
laravel ×2
php ×2
bash ×1
datatables ×1
django ×1
eloquent ×1
html ×1
laravel-5.1 ×1
laravel-5.4 ×1
mysql ×1
python ×1
sed ×1
ssh ×1