好吧所以我试图使用这些说明从命令行使用tar安装程序来安装VMware工具:http: //www.vmware.com/support/ws5/doc/ws_newguest_tools_linux.html#wp1118025
我在lubuntu上安装vmware工具,我使用vmplayer作为虚拟机运行.在步骤5之后,当在屏幕上响应配置问题时,它说
the installatinon of vmware tools 9.2.3 build-1031360 for linux completed sucessfully. you can devide to
remove this software form your system at any time by invoking the following command:
"/usr/bin/vmware-uninstall-tools.pl".
before running vmware tools for the first time, you need to configure it by invoking the following command:
"usr/bin/vmware-config-tools.pl". Do you want this program to invoke the command for you now?
[yes]
Run Code Online (Sandbox Code Playgroud)
我按下了Enter键并接受了默认的[yes]值,现在就说了
Before you can compile modules, you need to have the following installed... …
Run Code Online (Sandbox Code Playgroud) 这是我的forms.py:
class UploadImageForm(forms.ModelForm):
class Meta:
model = UserImages
fields = ['photo']
Run Code Online (Sandbox Code Playgroud)
这是我的models.py:
class UserImages(models.Model):
user = models.ForeignKey(User)
photo = models.ImageField(upload_to=get_file_path)
Run Code Online (Sandbox Code Playgroud)
这是我的看法:
def uploadImageView(request):
if request.method == 'POST':
form = UploadImageForm(request.POST, request.FILES)
if form.is_valid():
instance = form.save(commit=False)
instance.user = request.user
instance.save()
return redirect('/')
else:
form = UploadImageForm()
return render(request, 'uploadImagePage.html', {'uploadImageForm': form})
Run Code Online (Sandbox Code Playgroud)
但这只会保存正在上传的图像.如何保存图像的缩略图版本以及具有完全相同名称的图像的缩略图版本,除了后面带有"thumbail"字样?
我读过的教程说我可以做
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
Run Code Online (Sandbox Code Playgroud)
获取缩略图但在我的情况下,图像甚至还没有保存.
这是我的models.py:
class Notification(models.Model):
user = models.ForeignKey(User)
createdAt = models.DateTimeField(auto_now_add=True, blank=True)
read = models.BooleanField(default=False, blank=True)
class Meta:
abstract = True
class RegularNotification(Notification):
message = models.CharField(max_length=150)
link = models.CharField(max_length=100)
class FNotification(Notification):
# same as Notification
pass
Run Code Online (Sandbox Code Playgroud)
当我这样做时python manage.py makemigrations
,这就是它所说的:
Migrations for 'CApp':
0019_auto_20151202_2228.py:
- Create model RegularNotification
- Create model FNotification
- Remove field user from notification
- Add field f_request to userextended
- Delete model Notification
Run Code Online (Sandbox Code Playgroud)
首先,它说的很奇怪,Remove field user from notification
因为user
它仍然在我的Notiication
模型中(因此,如果有人能够弄清楚为什么它说"从通知中删除现场用户",那就太好了!)但是,当我继续前进并尝试时做python manage.py …
好的,所以我有我的实际笔记本电脑安装了vmware播放器.我正在运行lubuntu作为虚拟机,我在虚拟机上安装了django,我正在测试我的应用程序,所以我做了python manage.py runserver,我可以通过从我的VM访问127.0.0.1:8000来访问该应用程序,但是,如果我从实际的计算机(而不是VM)转到127.0.0.1:8000,它说"chrome无法连接到127.0.0.1:8000"..任何想法如何修复它?
我最近才开始学习ng-resource.我想知道在将常规AngularJS应用程序转换为使用ng-resource的应用程序时,我是否在正确的轨道上.
这是我的旧home.js
控制器(不使用ng-resource):
angular.module("HomeApp", ["BaseApp"])
.controller("MainCtrl", ["$http", "$window", "BaseService", function($http, $window, BaseService) {
var self = this;
BaseService.fetch.posts(function() {
self.posts = BaseService.posts;
self.cerrorMessages = BaseService.cerrorMessages;
});
self.like = function(id, postType) {
BaseService.like(id, postType, function() {
self.cerrorMessages = BaseService.cerrorMessages;
});
};
}]);
Run Code Online (Sandbox Code Playgroud)
这是我的旧base.js
(BaseService):
angular.module("BaseApp", [])
.factory("BaseService", ["$http", "$window", function($http, $window) {
var self = this;
self.posts = [];
self.cerrorMessages = [];
self.accessErrors = function(data) {
self.cerrorMessages = [];
for (prop in data) {
if (data.hasOwnProperty(prop)){
self.cerrorMessages.push(data[prop]);
}
} …
Run Code Online (Sandbox Code Playgroud) 昨天,我创建了这篇文章:DjangoRestFramework可浏览的api在本地与在服务器上部署时看起来不同?
基本上,当我这样做时python manage.py runserver
,这出现了:
但在我将其部署到AWS(eb deploy
)之后,这就是我访问网站时看到的内容:
上面帖子的答案提到这是因为我的静态文件丢失了.所以我搜索了如何在AWS上部署静态文件并遇到了这个教程:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-update-应用
"创建一个站点管理员"部分中,它提到的是,为了提供静态文件,我必须先定义STATIC_ROOT
中settings.py
(所以我做了:STATIC_ROOT = os.path.join(BASE_DIR, "ebdjangoapp/static/")
),然后我做了eb deploy
.但是,该站点看起来仍然与第二个图像相同(没有静态文件).然后我尝试做python manage.py collectstatic
(这创建了静态文件夹,rest_framework
里面有目录,包含css
文件等),然后又做eb deploy
了,但网站stil看起来和第二张图像相同.
为什么静态文件仍未显示?
请注意,我搜索过并发现这篇文章:Django app部署没有加载静态文件,答案是:
"然后,您要为settings.STATIC_ROOT
在settings.STATIC_URL
经选择的Web服务器,非常普遍的Nginx作为Apache的mod_wsgi的应用程序服务器后面的反向代理."
但我不知道Web服务器(nginx,反向代理,Apache-mod_wsgi)是如何工作的.我有一个我在本地运行的Django应用程序python manage.py runserver
,我有AWS弹性beanstalk.我通过这样做将我的Django应用程序部署到AWS eb deploy
.我需要采取哪些步骤才能在部署中显示静态文件(假设我不知道如何配置nginx,反向代理等).
在这个链接中(对于ReadOnlyField):http://www.django-rest-framework.org/api-guide/fields/#readonlyfield它说"当包含与一个相关的字段名称时,默认情况下使用此字段与ModelSerializer属性而不是模型字段".话虽如此,你能给我一个模型字段名称的例子,它是一个"属性",一个模型字段名称是一个"字段"吗?
在这里:http : //www.django-rest-framework.org/api-guide/viewsets/#modelviewset它说“ModelViewSet 类提供的操作是 .list()、.retrieve()、.create() 、.update()、.partial_update() 和 .destroy()。”
在这里:http : //www.django-rest-framework.org/api-guide/serializers/#modelserializer它说“ModelSerializer 类与常规 Serializer 类相同,除了:它包括 . create() 和 .update()。”
1)假设有一个 ViewsetUserViewSet
和 routeruser
和 serializer UserSerializer
。如果我发送了一个POST
to/user/
它叫UserViewSet
'screate()
还是UserSerializer
's create()
?
2)假设UserViewSet
有这个权限:
class NoCreate(permissions.BasePermission):
"""
No one can create this object.
"""
message = 'You do not have permission to complete the action you are trying to perform.'
def has_permission(self, request, view):
if view.action == …
Run Code Online (Sandbox Code Playgroud) django serialization django-rest-framework django-rest-viewsets
这是我尝试注册用户时调用的Django Rest Framework代码/视图:
def post(self, request):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Run Code Online (Sandbox Code Playgroud)
这是我的AngularJS代码,用于注册用户/调用上面发布的Django视图:
self.add = function() {
$http.post("/CMS/users", self.user) // this URL calls the Django view posted above
.error(function(data, status, headers, config) {
console.log(data);
for (prop in data) {
console.log(data[prop]);
};
})
.then(fetchUsers); // gets a list of existing users
console.log("User clicked submit with ", self.user);
};
Run Code Online (Sandbox Code Playgroud)
当我尝试注册已经存在的用户时,这是记录的内容:
Object {username: Array[1]}
username: Array[1]
0: "This username is already taken. Please, try again"
length: 1 …
Run Code Online (Sandbox Code Playgroud) javascript django angularjs django-rest-framework jsonobject
这是我的模特:
class Post(models.Model):
owner = models.ForeignKey(User, related_name="%(app_label)s%(class)s_set")
post = models.CharField(max_length=400)
class Meta:
abstract = True
class DS(Post):
location = models.ForeignKey(Location, blank=True, null=True, related_name="%(app_label)s%(class)s_set")
class Meta(Post.Meta):
abstract = True
class S(DS):
# same as DS
pass
Run Code Online (Sandbox Code Playgroud)
现在,当我打开Python shell并执行此操作时:
a = User.objects.get(username='a')
dir(a)
Run Code Online (Sandbox Code Playgroud)
然后这两个出现:
['myapps_set', 's_set']
Run Code Online (Sandbox Code Playgroud)
当我这样做时:
a.s_set.all()
Run Code Online (Sandbox Code Playgroud)
它返回一个S
对象,但是当我这样做时:
a.myapps_set.all()
Run Code Online (Sandbox Code Playgroud)
它返回三个S
对象(它返回的第一个S
对象与我返回的对象相同a.s_set.all()
.我的两个问题是,
1)为什么即使我特意做了owner = models.ForeignKey(User, related_name="%(app_label)s%(class)s_set")
,s_set
也可以用用户对象访问?
2)为什么他们会返回两组不同的对象(即如何myapps_set.all()
返回3(正确的答案)而s_set.all()
只返回一个?
django ×8
angularjs ×2
gcc ×1
image ×1
inheritance ×1
javascript ×1
jsonobject ×1
ngresource ×1
pillow ×1
thumbnails ×1
vmware ×1