django

Django “ImproperlyConfigured”, but not always

守給你的承諾、 提交于 2021-02-19 08:01:22
问题 I'm starting a new Django project, using Pycharm 4. I have defined the various models, and if I run tests, such as this, from django.test import TestCase from models import OwnerDatabase class TestZero(TestCase): def test_Settings(self): item=OwnerDatabase.objects.first everything works. But in a different part of the project, if I have this code (a standalone script) from models import OwnerDatabase the program balks with the following traceback File "/home/piffy/PycharmProjects/Russeau

django not found static files in the subfolder of static

情到浓时终转凉″ 提交于 2021-02-19 08:01:06
问题 django 1.6.5 My static files is under subfolder of static. djangoprj djangoprj settings.py urls.py wsgi.py __init__.py static myapp mystaticfiles ... apps myapp ... templates *.html ... In my templates file, I link static file as full path. <img src="/static/myapp/images/my.png" /> But those file are not found. I got 404 error. When change settings.py as STATIC='/static/myapp/' I can get those static files. But I am not want to do that. Why dose it not wok, when STATIC='/static/' ? Is there

Django “ImproperlyConfigured”, but not always

依然范特西╮ 提交于 2021-02-19 08:00:50
问题 I'm starting a new Django project, using Pycharm 4. I have defined the various models, and if I run tests, such as this, from django.test import TestCase from models import OwnerDatabase class TestZero(TestCase): def test_Settings(self): item=OwnerDatabase.objects.first everything works. But in a different part of the project, if I have this code (a standalone script) from models import OwnerDatabase the program balks with the following traceback File "/home/piffy/PycharmProjects/Russeau

Video Upload and display on a Django Website

痴心易碎 提交于 2021-02-19 07:58:07
问题 I have a model where I upload a video, i want to display the same in the browser but somehow I am not able to. Kindly help me. I made an app with the name deploy, where I am uploading the video and saving it. Kindly tell me where I am doing wrong and what should be done here. I want the video which was uploaded should be displayed on the page and there should be a option for download as well. I shall be extremely thankful for the help. My models.py file: class Video(models.Model): Video

How to show total pages in JSON response in Django Pagination?

旧时模样 提交于 2021-02-19 07:58:06
问题 I am currently working on pagination in Django restful framework. I am successfully done with pagination. but the problem I am facing is that "JSON response does not include information about total pages in my query and other information like total records etc". how can I include this information in my response. my view.py is from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger #######################View all mobiles @api_view(['GET']) def getAll_Mobiles(request): try:

customize error message in django rest

点点圈 提交于 2021-02-19 07:31:51
问题 i want to customize the error response from django rest framework. this is slandered error response from django rest.. { "style": [ "This field is required." ], "code": [ "code must be in 60 to 120 chars." ] } i want to customize it like.... { "style": [ "error_code":"20" "error_message":"This field is required." ], "code": [ "error_code":"22" "error_message":"code must be in 60 to 120 chars." ] } 回答1: I had the same problem in showing errors. First of all you should know that you can't use

customize error message in django rest

时光总嘲笑我的痴心妄想 提交于 2021-02-19 07:31:17
问题 i want to customize the error response from django rest framework. this is slandered error response from django rest.. { "style": [ "This field is required." ], "code": [ "code must be in 60 to 120 chars." ] } i want to customize it like.... { "style": [ "error_code":"20" "error_message":"This field is required." ], "code": [ "error_code":"22" "error_message":"code must be in 60 to 120 chars." ] } 回答1: I had the same problem in showing errors. First of all you should know that you can't use

django manytomany field using through and formwizard

馋奶兔 提交于 2021-02-19 06:43:36
问题 I am trying to create a pretty complicated form and break it up using formwizard. The first thing I am trying to do is get the ManyToManyField using through to display, Then I need to figure out how to make it all save. #models.py ---------------------- class Meat(models.Model): name = models.charField(max_length=200) company = models.CharField(max_length = 200) class Starch(models.Model): name = models.CharField(max_length=200) company = models.CharField(max_length=200) class Recipe(models

django-重写User模型

独自空忆成欢 提交于 2021-02-19 06:37:13
User模型有很多功能,验证什么的,重写需要满足下面的功能(基本上写注释的地方都是需要的) 开始: 创建一个重写user的app, 记得注册app startapp newauth from django.db import models from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager, User # AbstractBaseUser封装了密码加密存储, PermissionsMixin封装了各种n对n关系,ex:user and permission class UserManager(BaseUserManager): """ 实现User的 object功能 """ def _create_user(self, telephone, username, password, ** kwargs): user = self.model(telephone=telephone, username=username, ** kwargs) user.set_password(password) user.save() return user    # 创建普通用户 def create_user(self, telephone, username,

Easiest way to display uploaded (image)file?

匆匆过客 提交于 2021-02-19 06:27:30
问题 I'm trying to my first attempt at django file-uploading, and all i need at the moment is a way to display an uploaded image (png/jpg) to the user that uploaded. No need to save it anywhere. My views.py: (i'm using django forms, btw) if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): upFile = request.FILES['upFile'] f={"upFile":upFile} return render_to_response('upload2.html', f) And i can, as expected, display the name and size of my file in