我很难确定变量的类型,因为我在python2上使用并刚刚迁移到python3
from django.http import HttpResponse
def myview(request):
x = "Name"
print (x)
print type(x)
return HttpResponse("Example output")
Run Code Online (Sandbox Code Playgroud)
由于打印类型(x),此代码将引发错误.但是,如果您将该语法行更改为type(x).该类型不会在django的runserver上返回输出.
我对我们的 CDN 感到担忧,因为我们计划应用自定义域。我了解无法将 CNAME 记录映射到根域(例如 contoso.com)的部分。我想寻求一种解决方法,让我们说是的,我们已经将它分配给了 www.contoso.com。但是现在人们不再使用 www 子域,只会在 URL 地址栏中输入 constoso.com ,因此它只会返回 404,因为它没有被映射,因此会失去潜在客户。您建议的解决方案或解决方法是什么?
嗨,我在我的apache服务器上遇到问题,我希望我的python版本为3.5.1但是在3.2.3上运行.我试图在mod_wsgi.so上编译python 3.5版本但是我得到这个作为响应
/usr/local/opt/python-3.5.1/lib/libpython3.5m.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
Run Code Online (Sandbox Code Playgroud)
请注意,我的服务器是apache 2.2版本的debian wheezy
我在一篇文章中读到,理想的做法是包含一个 Location 标头,该标头指向新资源的 URL(通过 POST 新创建)。我的问题是我不知道如何包含它。
我使用 APIView 使用基于类的视图,视图中的代码是:
class ListArtists(APIView):
serializer_class = ArtistSerializer
def get(self, request, format=None):
_array = Artist.objects.filter()
serializer = self.serializer_class(_array, many=True)
if serializer.data:
_status = status.HTTP_200_OK
else:
_status = status.HTTP_204_NO_CONTENT
return Response(standardResponse(data=serializer.data), status=_status)
def post(self, request, format=None):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(standardResponse(data=serializer.data), status=status.HTTP_201_CREATED)
else:
return Response(standardResponse(errors=serializer.errors))
artist = ListArtists.as_view()
Run Code Online (Sandbox Code Playgroud)
网址.py
from django.conf.urls import url, include
from store import views
urlpatterns = [
url(r'^artists/', views.artist, name='artists-list'),
]
Run Code Online (Sandbox Code Playgroud)
聚苯乙烯
每次我使用 Advanced REST Client 发出请求时,我收到的响应如下:
Date: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建自动化测试,我想在TestCase中检查是否有一个位置标头,它应该基于我在views.py中的代码(已经在Advanced REST Client中对其进行了测试)。但是,我无法在tests.py中解析它
这是我的代码:
from rest_framework import status
from rest_framework.test import APITestCase
url_1 = reverse('artists-list')
class ArtistTest(APITestCase):
# Check the response if there is no data
def test_get(self):
# Checks the artists
# self.client attribute will be an APIClient instance
# Basically it will act as a client
response = self.client.get(url_1)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(response.content, '') # There should be no data
# self.assertEqual(len(data), 0)
# print ("%s.%s DONE - 1" % (self.__class__.__name__, inspect.stack()[0][3]))
def test_post(self):
_data = {"name": "50 Cent", …
Run Code Online (Sandbox Code Playgroud) 我正在练习芹菜,我想将我的任务分配到特定的队列,但是无法正常工作
我的__init__.py
import os
import sys
from celery import Celery
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(CURRENT_DIR)
app = Celery()
app.config_from_object('celery_config')
Run Code Online (Sandbox Code Playgroud)
我的celery_config.py
amqp = 'amqp://guest:guest@localhost:5672//'
broker_url = amqp
result_backend = amqp
task_routes = ([
('import_feed', {'queue': 'queue_import_feed'})
])
Run Code Online (Sandbox Code Playgroud)
我的tasks.py
from . import app
@app.task(name='import_feed')
def import_feed():
pass
Run Code Online (Sandbox Code Playgroud)
我如何管理工人:
celery -A subscriber1.tasks worker -l info
Run Code Online (Sandbox Code Playgroud)
我的客户的__init__.py
:
import os
import sys
from celery import Celery
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(CURRENT_DIR)
app = Celery()
app.config_from_object('celery_config')
Run Code Online (Sandbox Code Playgroud)
我的客户的celery_config.py:
from kombu.common import Broadcast …
Run Code Online (Sandbox Code Playgroud) 在 Django Rest Framework 中,我使用了序列化器、视图集和路由器方法。每当我在 django Rest 框架的 API 视图中发布故意错误时,它都会抛出完整性错误。有没有办法尝试捕获错误,例如如果数据中没有错误,则继续保存,但是如果有错误,则会抛出包含错误列表的 JSON 响应,例如:
[{'section':'This field can not be blank', 'first_name':'This field can not be blank', 'middle_name':'This field can not be blank', 'last_name':'This field can not be blank'}]
Run Code Online (Sandbox Code Playgroud)
模型.py
from django.db import models
# Create your models here.
# class AuditTable(models.Model):
# date_created = models.DateTimeField(auto_now_add=True)
# test_field = models.CharField(max_length=50, null=True, blank=True)
class Section(models.Model):
name = models.CharField(max_length=50, default=None)
def __str__(self):
return self.name
class Student(models.Model):
section = models.ForeignKey(Section, default=None)
first_name = models.CharField(max_length=50, default=None)
middle_name …
Run Code Online (Sandbox Code Playgroud) 用户如何在多个设备中登录,因为我们拥有的只是我们的django应用程序上的单个令牌身份验证.作为经过身份验证的用户,当我在Google Chrome上登录时,它工作正常,但是当我在mozilla时间访问并且我在Chrome注销时,已经创建的令牌在注销时被删除,所以当我在mozilla登录时,令牌已经是我们无法登录mozilla并在控制台上抛出Forbidden响应.
嗨哪个更好?有什么不同?优缺点都有什么?
以下是两者之间的比较代码:
范围:{ngModel:'='}
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="app">
<input ng-model="code"></my-directive>
</div>
<script type="text/javascript">
app = angular.module('app', []);
app.directive('input', function(){
return {
scope: {
ngModel: '='
},
link: function(scope, element, attrs){
scope.$watch('ngModel', function(value){
console.log(value);
})
}
}
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
require:'ngModel',
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="app">
<input ng-model="code"></my-directive>
</div>
<script type="text/javascript">
app = angular.module('app', []);
app.directive('input', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel){
attrs.$observe('ngModel', function(value){
scope.$watch(value, function(newValue){
console.log(newValue);
});
});
} …
Run Code Online (Sandbox Code Playgroud) 我在由 Vue CLI 4 提供支持的 VueJS 应用程序中创建了两个插件,但是当我尝试在我的页面中使用它时,只有一个可以工作
| plugins
|-- axios.vue
|-- authentication.vue
Run Code Online (Sandbox Code Playgroud)
axios.vue
| plugins
|-- axios.vue
|-- authentication.vue
Run Code Online (Sandbox Code Playgroud)
身份验证.vue
import Vue from "vue";
Plugin.install = function(Vue) {
Vue.prototype.$myName = "Dean Armada";
};
Vue.use(Plugin);
export default Plugin;
Run Code Online (Sandbox Code Playgroud)
主文件
import Vue from "vue";
Plugin.install = function(Vue) {
Vue.prototype.$name = "Chris Guinto";
};
Vue.use(Plugin);
export default Plugin;
Run Code Online (Sandbox Code Playgroud)
说明.vue
import axios from "./plugins/axios.js";
import authentication from "./plugins/authentication.js";
Vue.use(axios);
Vue.use(authentication);
Run Code Online (Sandbox Code Playgroud)
console.log(this.$name)
未定义Vue.use(axios)
了console.log(this.$name)
将努力使其输出将是“克里斯Guinto”,另一种是不明确的,因为axios
插件未激活那么我怎样才能让它们同时工作呢?
django ×5
python ×2
angularjs ×1
apache ×1
azure ×1
azure-cdn ×1
celery ×1
javascript ×1
python-3.5 ×1
python-3.x ×1
rest ×1
vue-cli-4 ×1
vuejs2 ×1