我正在使用Django构建学生管理系统.
在此代码中,用户name=StudentName&grade=Grade&id=StudentID&phone=ParentPhoneNumber&report=StudentReportNumber使用该decrypt()方法搜索具有加密查询的学生
.
以下是两种方法,即处理查询的方法和显示学生资料的方法.
查询中的数据不会保存到数据库中,但会用于从数据库中查询学生详细信息.
def process_query(request):
# process the query from the url /?details={{ some hashes here }}
if request.method == 'GET':
raw_deatils = request.GET.get('details', None)
if raw_deatils:
details = decrypt(raw_deatils)
# decrypt is a function that is defined
# in the utils which takes the input string,
# check predeifined tests to test if valid.
# and return the decrypted query string else None
if details:
# now the decrypted message looks something like …Run Code Online (Sandbox Code Playgroud) 这个问题已经在 StackOverflow 上问过了,
问的问题可以追溯到 2013 年,现在是 2015 年,Django 快速成长。
截至 2015 年,在 Django 1.8 中使用 mongodb 的情况如何?
Django 是否开箱即用地支持 Monogodb(使用数据库适配器)?还是应该使用像 django-nonrel 这样的其他发行版?
django non-relational-database mongodb django-nonrel django-1.8
在模型中,我有一个字幕字段,None如果给定对象的字段没有值,则填充该字段.
有没有办法将值显示给自定义的东西(比如显示Not Available或Not Applicable不显示)(None)
领域
sub_title = models.CharField(max_length=255, null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)
管理
list_display = 'sub_title',
Run Code Online (Sandbox Code Playgroud)
PS:我想None在数据库中,而管理面板上的自定义值.
谢谢
这个问题不是上述问题的重复,我不是要求一种方法来比较实例,而是要求方法assertEqual,以及它的目的是什么.
assertEqual(a, b)检查是否a == b返回True或False,
文件说,
测试第一和第二是相等的.如果值不相等,则测试将失败.
我assertEqual在一个简单的课上运行三个测试,
上课时考试
class Car:
def __init__(self, name):
self.name = name
Run Code Online (Sandbox Code Playgroud)
TestCase
class CarTest(unittest.TestCase):
def test_diff_equal(self):
car1 = Car('Ford')
car2 = Car('Hyundai')
self.assertEqual(car1, car2)
def test_name_equal(self):
car1 = Car('Ford')
car2 = Car('Ford')
self.assertEqual(car1, car2)
def test_instance_equal(self):
car1 = Car('Ford')
self.assertEqual(car1, car1)
Run Code Online (Sandbox Code Playgroud)
结果是
F.F
======================================================================
FAIL: test_diff_equal (cartest.CarTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "cartest.py", line 10, in test_diff_equal
self.assertEqual(car1, car2)
AssertionError: <car.Car instance at …Run Code Online (Sandbox Code Playgroud) 我正在尝试在学习Angular 2的同时设置一条简单的路线,每当我点击一个链接时,浏览器就会被路由到新的路线,但浏览器会重新请求所有资源(不像单页应用程序那样).
我的索引文件,
<!--... . . various scripts and styles . . . . . --->
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<app></app>
</body>
Run Code Online (Sandbox Code Playgroud)
应用来源,
main.ts
import {bootstrap} from 'angular2/platform/browser';
import {RoutingApp} from './routing/routing.app'
import {ROUTER_PROVIDERS} from 'angular2/router'
bootstrap(RoutingApp, [ROUTER_PROVIDERS]);
Run Code Online (Sandbox Code Playgroud)
RoutingApp
import {Component} from "angular2/core"
import {RouteComponent} from './route.component'
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
@Component({
selector : 'app', …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个plnkr来演示我想要问的问题
我在网络应用程序中有一些组件,
父组件, App
@Component({
selector: 'my-app',
providers: [],
template: `
<div class="main-container">
<h2>This is the base. This div must be seen on app pages</h2>
<a [routerLink]="['Home']"> Home </a> |
<a [routerLink]="['Users']"> Users </a> |
<a [routerLink]="['Contact']"> Contact </a>
</div>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{
path: '/',
name: 'Home',
component: HomeComponent,
useAsDefault: true
},
{
path: '/users/...',
name: 'Users',
component: UsersComponent
},
{
path: '/contact',
name: 'Contact',
component: ContactComponent
}
])
export class App {
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试开始使用芹菜,但我无法完成我的任务.我安装了django-celery-beat和celery4.
我的设置文件.
已安装的应用程序(使用芹菜包)
...
'django_celery_beat',
'django_celery_results'
Run Code Online (Sandbox Code Playgroud)
芹菜配置
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
Run Code Online (Sandbox Code Playgroud)
celery.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sandbox.settings')
app = Celery('sandbox')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration …Run Code Online (Sandbox Code Playgroud) 我想OPTIONS全局(在所有 API 端点上)禁用使用 Django Rest Framework (DRF) 构建的 API 上的方法
目前有OPTIONS电话返回,
{
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"renders": [
"application/json"
],
"name": "Login Oauth2",
"description": ""
}
Run Code Online (Sandbox Code Playgroud)
这是我不希望有人偷看的东西。我想返回一个空白字符,就像 github 在其 API 或其他东西上所做的那样。
我试过
@api_view(['POST'])
def my_method(request):
if request.method == 'OPTIONS':
return Response()
Run Code Online (Sandbox Code Playgroud)
在基于函数的视图上,它返回一个但检查标题显示,
Allow ?POST, OPTIONS, OPTIONS
Run Code Online (Sandbox Code Playgroud)
其中有一个重复的OPTIONS.
我如何实现它?谢谢。
我在这里尝试过以前的答案.我只能找到几个子集.
这是我正在处理的代码和示例.
s = "{| mySting0 |} The {| mySting1 |} The {| mySting2 |} The {| mySting3 |} make it work "
result = re.findall('{\|(.*)|}', s)
Run Code Online (Sandbox Code Playgroud)
输出是,
[' mySting0 |} The {| mySting1 |} The {| mySting2 |} The {| mySting3 |} make it work ']
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个模型,我必须记录一个PositiveSmallIntegerField对象,每天更新相关的分数.
class Student(models.Model):
name = models.CharField(max_length=20)
grade = models.ForeignKey(Grade)
rank = ??
Run Code Online (Sandbox Code Playgroud)
具有此模型的对象数量永远不会超过100,并且分数/等级必须保留180天.该数据库是Postgresql 9.2.
每天从另一个应用程序的分数计算排名,我想存储在与学生模型相关的数据库中,我坚持模型设计,我不知道,应该为排名做些什么?Django中有重复的字段吗?
任何线索或经验将非常感激
谢谢.
数据库必须看起来像这样,
+---------+-------+----------+----------+----------+----------+----------+----------+
| Student | Grade | 08-01-15 | 08-02-15 | 08-03-15 | 08-04-15 | 08-05-15 | 08-06-15 |
+---------+-------+----------+----------+----------+----------+----------+----------+
| Alex | 5 | 2 | 1 | 1 | 2 | 3 | 2 |
| John | 5 | 3 | 2 | 3 | 4 | 2 | 4 |
| Susan | 5 | 1 …Run Code Online (Sandbox Code Playgroud) python ×7
django ×6
angular ×2
typescript ×2
assert ×1
celery ×1
celerybeat ×1
django-1.8 ×1
django-admin ×1
django-urls ×1
django-views ×1
mongodb ×1
postgresql ×1
regex ×1
rest ×1
unit-testing ×1