我试图使用bootstrap中心表.
这是html:
<div class="container-fluid">
<table id="total votes" class="table table-hover text-centered">
<thead>
<tr>
<th>Total votes</th>
<th> = </th>
<th>Voter A</th>
<th> + </th>
<th>Voter B</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ total_votes }}</td>
<td> = </td>
<td>{{ total_voter_a }}</td>
<td> + </td>
<td>{{ total_voter_b }}</td>
</tr>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,无论我如何调整css
,桌子仍然与左边对齐.我确定我错过了一些简单的事情.我还以为container-fluid
会让这个表跨越整个页面.
这是css:
.table th {
text-align: center;
}
.table {
border-radius: 5px;
width: 50%;
float: none;
}
Run Code Online (Sandbox Code Playgroud) 我有一个表格产品,显示一组产品的信息.
<table id="item_table" class="table table-sm table-hover table-bordered">
<thead class="thead-inverse">
<tr>
<th colspan="2">Date</th>
<th colspan="6">Product name</th>
<th colspan="2">Category</th>
<th colspan="2">Amount</th>
</tr>
</thead>
<tbody>
{% for item in product_list %}
<tr>
<td colspan="2">{{ item.date }}</td>
<td id="item_name_format" colspan="6">{{ item.name }}</td>
{% if item.category_id %}
<td id="item_name_format" colspan="2">{{ item.category_id.level1_desc }}</td>
{% endif %}
<td id="item_amt_format" colspan="2">${{ item.amount|intcomma }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我正在使用下面的Ajax调用更新表.
$(document).ready(function(){
// Submit post on submit
$('.item_num').on('click', function(event){
event.preventDefault();
var item_num = $(this).attr('id');
update_item(item_num);
});
function update_item(item_num) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用customUser安装django-registration-redux.
我已将其包含在我的settings.py中:
AUTH_USER_MODEL = 'app.customUser'
Run Code Online (Sandbox Code Playgroud)
注册表位于目录../registration/forms.py中:
from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.forms import UserCreationForm
from .users import UserModel, UsernameField
User = UserModel()
class RegistrationForm(UserCreationForm):
required_css_class = 'required'
email = forms.EmailField(label=_("E-mail"))
class Meta:
model = customUser
fields = ('email')
Run Code Online (Sandbox Code Playgroud)
此外,models.py还具有以下内容:
from __future__ import unicode_literals
from django.db import models
# Create your models here.
import datetime
import hashlib
import random
import re
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.db …
Run Code Online (Sandbox Code Playgroud) 我正在使用'rest_serializer'模块实现Django REST API框架:
当前输出为:
{
"count": 86,
"next": "http://127.0.0.1:8000/state/?page=2",
"previous": null,
"results": [
{
"state_name": "Alaska"
},
{
"state_name": "California"
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
如何将其显示为json列表:
[
"Alaska",
"California",
...
]
Run Code Online (Sandbox Code Playgroud)
以下是我的序列化器:
from .models import States
from rest_framework import serializers
class StateSerializer(serializers.ModelSerializer):
class Meta:
model = State
fields = ('state_name',)
Run Code Online (Sandbox Code Playgroud)
view.py
class StateViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows groups to be viewed or edited.
"""
queryset = States.objects.values('state_name').distinct();
serializer_class = StateSerializer
Run Code Online (Sandbox Code Playgroud) 我按照 Django 的方式设置了自定义用户管理器,但仍然收到属性错误。我不确定还有什么问题。
class UserManager(BaseUserManager):
def create_user(self, email, date_of_birth, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, date_of_birth, password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(email,
password=password,
date_of_birth=date_of_birth
)
user.is_admin = True
user.save(using=self._db)
return user
class User(AbstractBaseUser): …
Run Code Online (Sandbox Code Playgroud) 我有一个模型,每个条目都有一个日期.如何使用queryset查找具有最早日期的条目?这不依赖于'pk',因为我可以在以后添加一个具有更早日期的行.
这是我到目前为止,它似乎没有工作:
Model.objects.get(min(date))
Run Code Online (Sandbox Code Playgroud)
谢谢.
我设置了两个类,其中一个用户可能有多个访问密钥。
class User(models.Model):
first_name = models.CharField(max_length=50)
middle_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField()
password = models.CharField(max_length=50)
birthday = models.DateField()
def __str__(self):
return self.first_name+" "+self.last_name
class pets(models.Model):
user = models.ForeignKey('User')
type = models.CharField(max_length=50)
color = models.CharField(max_length=50)
def __str__(self):
return self.type
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 loaddata 通过如下所示的 json 文件预加载包含数据的表:
[
{
"fields": {
"first_name": "John",
"last_name": "Doe",
"middle_name": "G",
"birthday": "1900-07-21",
"password": "goforit123",
"email": "John.Doe@gmail.com"
},
"model": "account_data.user",
"pk": 1
},
{
"fields": {
"user": "????"
"type": "dog",
"color": "blue"
},
"model": "account_data.pets", …
Run Code Online (Sandbox Code Playgroud) 我有一个名单:
name_list = ['John', 'Bill', 'Charlie']
Run Code Online (Sandbox Code Playgroud)
我想过滤name字段匹配任何这些名称的结果.如何在queryset中实现它?我使用的代码是:
Special_group = People.objects.filter(name=name_list(?))
Run Code Online (Sandbox Code Playgroud)
谢谢.
目前,我有两个从 base.html 扩展的 html 模板:
page1.html:
{% extends 'dashboard/base.html' %}
{% block tittle %} Dashboard1 {% endblock %}
... code ...
Code_block_1
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
page2.html:
{% extends 'dashboard/base.html' %}
{% block tittle %} Dashboard2 {% endblock %}
... code ...
Code_block_1
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
两个 html 共享相同的 Code_block_1。
我正在考虑创建另一个名为 Code_block_1.html 的 html 来合并这段重复的代码。然后,将 Code_block_1.html 插入到 page1.html 和 pag2.html 中。Django 只允许你扩展一次。我该如何解决这个问题?
谢谢。
我有一个 JSON 文件:
['0': XXX, '1': YYYY]
Run Code Online (Sandbox Code Playgroud)
我想通过 jquery 将它提取到一个只有值的数组中。
['XXX', 'YYYY']
Run Code Online (Sandbox Code Playgroud)
做这个的最好方式是什么?
.makeArray 似乎不起作用。
我想删除
results = Model.objects.filter(condition - satisfied... etc.)
Run Code Online (Sandbox Code Playgroud)
然后我遍历查询集并在我浏览代码时删除每个对象:
for a in results:
### code ###
results.exclude(id=a.id)
Run Code Online (Sandbox Code Playgroud)
无论我如何排除,结果对象都不会改变。当我遍历查询集时,有没有办法“弹出”它们?
我目前有一个采用Unicode格式的日期:
k = u'2015-02-01'
Run Code Online (Sandbox Code Playgroud)
我试图将其添加到列表并将其更改为字符串:
date = []
date.append(str(k))
Run Code Online (Sandbox Code Playgroud)
然后,我想将此作为Django上下文传递给我的模板。
但是,日期显示如下:
'2015-02-01'
Run Code Online (Sandbox Code Playgroud)
我如何摆脱$#39;并用双引号(“)替换?
非常感谢。
我有一个人物模型。
class Person(models.Model):
name_first = models.CharField(max_length=100)
name_middle = models.CharField(max_length=100, null=True, blank=True)
name_last = models.CharField(max_length=100)
date_birth = models.DateField(null=True, blank=True)
date_death = models.DateField(null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其扩展到音乐界的不同角色:作曲家,表演者和赞助人。
一个人可以是一个,两个或所有三个角色。如果某人是表演者,我还需要为该人分配一种或多种乐器。在实例化时,您可能不知道某人是否是表演者。否则他们的角色会随着时间而改变。
我希望能够搜索并显示一个人(如果他是三个人)既是作曲家,钢琴家又是赞助人。例如:贝多芬是指挥,作曲家和钢琴家。
我对实现的最初想法是继承Person类。
class Composer(Person):
pass
class Performer(Person):
instrument = models.ManyToManyField(Instrument, verbose_name=_('instrument'), blank=True,)
class Patron(Person):
pass
class Instrument(models.Model):
name = models.CharField(max_length=100, null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
问题1:我应该改用某种抽象模型吗?如果是这样,我将如何处理?
问题2:我如何寻找一个人,并知道他们是否是作曲家,赞助人和/或表演者,以及他们是哪种表演者。
谢谢。
django ×11
html ×2
jquery ×2
json ×2
python ×2
ajax ×1
css ×1
django-apps ×1
django-views ×1
javascript ×1
python-2.7 ×1