小编ily*_*yew的帖子

Django 中的自定义用户注册表单

我已经为 django 创建了自定义用户注册表单,但它不起作用:-(

我创建了 LOGINSYS 应用程序来操纵用户(登录、个人资料页面、注册)

我的 forms.py 看起来像这样:

    #-*- coding:utf-8 -*-
    from django import forms
    from django.contrib.auth.models import User
    from django.contrib.auth.forms import UserCreationForm
    from datetime import date, timedelta
    
    class MyRegistrationForm(UserCreationForm):
        def get_image_path(self, filename):
            path = ''.join([date.today().strftime('../static/user_image/%Y/%m/%d/'), translit.slugify(filename), ".jpg"])
            return path
    
        first_name = forms.CharField (required = True)
        last_name = forms.CharField (required = True)
        telephone = forms.CharField (required = True)
        email = forms.EmailField (required = False)
        #user_image = forms.ImageField(path = get_image_path, required = False, allow_empty_file = True )
    
    
        class Meta:
            model …
Run Code Online (Sandbox Code Playgroud)

django django-templates django-models

6
推荐指数
1
解决办法
2544
查看次数

如何将模板变量传递给 Django 模板中的切片过滤器

我正在尝试使用变量在 django 模板中切片循环

通常的方式

{% for article in module.module_article_key.module_article_category.article_category_key.all|slice:":2" %}
    {{ article.article_title }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

需要什么

{% for article in module.module_article_key.module_article_category.article_category_key.all|slice:":module.module_article_key.module_article_count" %}
    {{ article.article_title }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

所以我们有工作变量{{ module.module_article_key.module_article_count }}

通常这个变量给出了为这个模块存储的整数值,但是我用它来切片循环 - 没有任何反应

python django django-templates

4
推荐指数
1
解决办法
2081
查看次数

标签 统计

django ×2

django-templates ×2

django-models ×1

python ×1