django

Django Models Radio Input

久未见 提交于 2021-02-20 18:58:06
问题 I am trying to incorporate radio buttons in my form. In my forms.py I have the following fields for the form : class ProfileForm(forms.ModelForm): class Meta: model = Profile fields = ['first_name', 'last_name', 'gender'] In my models.py : user = models.ForeignKey(User, db_column='user_id') first_name = models.CharField(max_length=250) last_name = models.CharField(max_length=250 GENDER = (('M', 'Male'), ('F', 'Female'), ('O', 'Other')) gender = models.CharField(max_length=1, choices=GENDER,

Unable to override django-allauth templates

删除回忆录丶 提交于 2021-02-20 18:50:46
问题 I'm trying to override the default django-allauth templates. I've copied the templates from the allauth folder in my site-packages to my applications template directory. The structure is as follows myapp --templates ----account ----admin ----socialaccount ----www ----base.html My settings.py has the TEMPLATE_DIRS set TEMPLATE_DIRS = ( os.path.join(BASE_DIR, "templates"), ) As per this answer I'm loading my application before allauth. Making any changes to the templates in my directory doesn't

Unable to override django-allauth templates

萝らか妹 提交于 2021-02-20 18:50:13
问题 I'm trying to override the default django-allauth templates. I've copied the templates from the allauth folder in my site-packages to my applications template directory. The structure is as follows myapp --templates ----account ----admin ----socialaccount ----www ----base.html My settings.py has the TEMPLATE_DIRS set TEMPLATE_DIRS = ( os.path.join(BASE_DIR, "templates"), ) As per this answer I'm loading my application before allauth. Making any changes to the templates in my directory doesn't

Django AttributeError: Form object has no attribute '_errors'

梦想的初衷 提交于 2021-02-20 11:40:56
问题 I'm overriding the init method in my form andthis is now returning an error 'TransactionForm' object has no attribute '_errors' . I would expect this to work because I've included super in my init , however perhaps I don't understand how to use this correctly. An explanation would be appreciated. What do I need to do to get form.errors working? Full traceback Traceback: File "C:\Program Files\Python36\lib\site-packages\django\core\handlers\exception.py" in inner 35. response = get_response

Django AttributeError: Form object has no attribute '_errors'

南楼画角 提交于 2021-02-20 11:39:41
问题 I'm overriding the init method in my form andthis is now returning an error 'TransactionForm' object has no attribute '_errors' . I would expect this to work because I've included super in my init , however perhaps I don't understand how to use this correctly. An explanation would be appreciated. What do I need to do to get form.errors working? Full traceback Traceback: File "C:\Program Files\Python36\lib\site-packages\django\core\handlers\exception.py" in inner 35. response = get_response

Django web-poll系统

不问归期 提交于 2021-02-20 11:38:49
通过一个调查问卷的例子来学习Django,它主要包括两部分: 一个公共站点,允许用户查看问卷并投票 一个管理员站点,允许添加、修改和删除问卷 假设你已经安装了Django,可以使用 python -m django --version 来检测 创建一个项目 通过 django-admin startproject mysite 创建一个项目 该命令会在当前目录创建一个 mysite 目录,切记不要用 django 这个关键字来给项目命名。 创建得到的目录结构如下: mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py 接下来一一解释这些文件的作用: 外部的 mysite/ 根目录是整个项目的容器,它的名字并不重要,你可以自行重命名; manage.py :一个命令行的组件,提供多种方式来和Django项目进行交互 内部的 mysite/ 目录是项目实际的Python包,它的名字就是将来 import 时要用的,比如 mysite.urls mysite/settings.py :当前项目的配置文件 mysite/urls.py :当前项目的 url 声明语句 mysite/wsgi.py :WSGI兼容的web服务器的entry-point 开发服务器 通过 python manage.py

django 发布会签到系统web开发

柔情痞子 提交于 2021-02-20 10:54:50
  引言   最近学习了虫师的发布会签到系统demo,结合自己所学django知识,对demo重新塑造了一下。也是为了练练手,巩固知识。现在就分享一下成果~   Django工作流   学习django web开发,先来简单了解一下django的工作机制,请看下图: 简单说明: 用户通过浏览器访问:http://127.0.0.1:8000/index,首先运行的是urlpatterns程序,通过url路由找到对应的视图函数views.py,视图函数处理所有逻辑和数据,并且将用户要的数据经过函数处理后通过index.html返回给浏览器前的用户看。    详情流程   从用户通过浏览器访问→函数处理→数据展示,整个形成一个闭关。   MVC是众所周知的模式,即:将应用程序分解成三个组成部分:model(模型),view(视图),和 controller(控制 器)。其中: M——管理应用程序的状态(通常存储到数据库中),并约束改变状态的行为(或者叫做“业务规则”)。 C——接受外部用户的操作,根据操作访问模型获取数据,并调用“视图”显示这些数据。控制器是将“模型”和“视图”隔离,并成为二者之间的联系纽带。 V——负责把数据格式化后呈现给用户。   Django也是一个MVC框架。但是在Django中,控制器接受用户输入的部分由框架自行处理(C交给用户),所以 Django

Edit Django admin logout template?

↘锁芯ラ 提交于 2021-02-20 10:31:53
问题 I want to make a very small change to the Django admin logout page. I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file. I have set up a new template at templates/registration/logged_out.html . The content of this file is as follows: {% extends "registration/logged_out.html" %} {% block content %} <p>Thanks for using the site.</p> <p><a href="../">Log in again</a></p> <p><a href="/">Return to the home page</a></p> {%

Edit Django admin logout template?

岁酱吖の 提交于 2021-02-20 10:31:05
问题 I want to make a very small change to the Django admin logout page. I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file. I have set up a new template at templates/registration/logged_out.html . The content of this file is as follows: {% extends "registration/logged_out.html" %} {% block content %} <p>Thanks for using the site.</p> <p><a href="../">Log in again</a></p> <p><a href="/">Return to the home page</a></p> {%

How to get COUNT query in django

我只是一个虾纸丫 提交于 2021-02-20 08:30:46
问题 To get a query in django I can do: >>> print User.objects.all().query SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` However, how would I get the query it builds when doing a COUNT? >>> User.objects.all().count().query Traceback (most recent call last):