我想在Django中创建一个字段models.py
,它将作为下拉列表呈现,用户可以从那里选择选项.
如果我有5个选择:
我应该如何编写代码models.py
,Forms.py
以便模板将其呈现为下拉元素?
我有一个 css 文件,我想在其中导入另一个 css 文件。我怎样才能在 Django 中做到这一点?
这是我的 style.css 文件,我想在其中导入 owl.carousel.css 。
@import url("owl.carousel.css");
body {
margin: 0;
padding: 0;
color: #34495E;
font-family: 'Source Sans Pro', sans-serif;
font-size: 14px;
line-height: 21px;
position: relative;
background: #fff;
}
Run Code Online (Sandbox Code Playgroud)
我在模板上使用 {% load static %} 来链接 style.css 但如何在 css 中导入 css ?
<link href="{% static "assets/css/style.css" %}" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud) 我编写了一个 gitlab-ci.yml 文件,其中包含多个 gitlab 作业和阶段。当代码合并到特定的 git 分支并且安排一些作业时,某些作业会在该分支上运行。
我想在 Gitlab 中创建一个计划的 CI/CD 管道,它只包含特定的计划作业,而不包含所有计划的作业。那可能吗?
例如,这是我的 gitlab-ci.yml 文件。
stages:
build
test
deploy
scheduled-test-1
scheduled-test-2
scheduled-test-3
build:
script:
- echo $Service_Version
only:
- develop
except:
- schedules
test:
script:
- echo $Service_Version
only:
- develop
except:
- schedules
deploy:
script:
- echo $Service_Version
only:
- develop
except:
- schedules
scheduled-test-1:
script:
- echo $Service_Version
only:
- schedules
scheduled-test-2:
script:
- echo $Service_Version
only:
- schedules
scheduled-test-3:
script:
- echo $Service_Version
only:
- schedules
Run Code Online (Sandbox Code Playgroud)
现在,当我创建计划时,所有三个计划测试都会在管道上看到。我想创建三个计划,分别包含scheduled-test-1、scheduled-test-2和scheduled-test-3。这怎么可能?
我在heroku上执行syncdb时遇到问题.我有一个自定义用户模型,当我尝试同步时,heroku给出了这个错误.
django.db.utils.ProgrammingError: relation "auth_group" does not exist
Run Code Online (Sandbox Code Playgroud)
我尝试过python manage.py makemigrations但没有任何问题得到解决.帮我找到解决方案.
gitlab 中有没有一种方法或设置可以允许用户从预先批准的分支创建标签?
换句话说,如果我尝试在 Gitlab 上创建新标签,我会获得“创建自”字段的 Git 修订版本的特定列表。
如何向 Django 中的输入标签添加多个属性?
示例:要添加单个属性,我可以使用此代码
email = forms.EmailField(
widget = forms.TextInput(attrs={'placeholder': 'Email'}))
Run Code Online (Sandbox Code Playgroud)
但是如果我想添加“类”、“大小”和“占位符”属性,那么在 Django 表单中的做法是什么?
我正在努力访问 django 中的会话变量。
我有两个不同的应用程序custom_user 和article。在我的custom_user的views.py文件中,我声明了一个会话变量。
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
request.session['email'] = user.email
return render_to_response(request, "loggedin.html", locals(),context_instance=RequestContext(request))
else:
return HttpResponseRedirect('/accounts/invalid')
Run Code Online (Sandbox Code Playgroud)
在我的文章应用程序的views.py中,我像这样访问它。
def articles(request):
return render_to_response('articles.html',
{'articles':Article.objects.all().order_by('-id'),'last':Article.objects.earliest('-pub_date'), 'loggedin':request.session.email})
Run Code Online (Sandbox Code Playgroud)
我的articles.html 文件继承了base.html 文件,并且我使用{{loggedin}} 来访问变量。我已经使用了 {{request.session.email}} 但这也不起作用
我最终想要做的是在我的导航栏中显示在我的网站上登录的用户的电子邮件地址(位于 base.html 文件中)。
我只获取在 auth_view 函数中呈现的loggedin.html 文件中的user.email 值。但不在任何其他 html 文件中。
我想在Django模板上只打印日期.这是我的模特.
class Comment(models.Model):
name = models.ForeignKey(User)
body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True)
article = models.ForeignKey(Article)
Run Code Online (Sandbox Code Playgroud)
现在要在模板上打印日期和时间,我可以使用{{object.pub_date}}进行打印.但我只想打印日期,而不是时间.有没有办法在Django模板中这样做?