您好我正在使用django和postgresql.我收到了上述错误.我有这样的数据库设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db',
'USER': 'xxx',
'PASSWORD':'xxxx',
'HOST':'localhost',
'PORT':'5432',
}
}
Run Code Online (Sandbox Code Playgroud)
对于像sqlite这样的问题,我只能删除db(mydatabase),但这次我看不到我的数据库在哪里.
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'tastypie')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/ebagu/main/views.py" in index
47. post_list = sorted(post_list, key=lambda x: x.get_score(), reverse=True)
File "/env/local/lib/python2.7/site-packages/django/db/models/query.py" in __iter__
162. self._fetch_all() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ajax发送我的评论表单,现在当用户插入评论时,整个页面都会刷新.我希望在没有页面刷新的情况下很好地插入它.所以我尝试了很多东西,但没有运气.因为我是初学者,所以我试着遵循许多教程链接; https://realpython.com/blog/python/django-and-ajax-form-submissions/ https://impythonist.wordpress.com/2015/06/16/django-with-ajax-a-modern-client-服务器通信实践/评论页-1 /#评论1631
我意识到我的问题是我很难在views.py和forms.py中操作我的代码因此在进行客户端编程(js和ajax)之前我需要再次设置我的后端(python代码)来设置阿贾克斯.有人可以帮我这个吗?我不知道如何设置我的后端....
<div class="leave comment>
<form method="POST" action='{% url "comment_create" %}' id='commentForAjax'>{% csrf_token %}
<input type='hidden' name='post_id' value='{{ post.id }}'/>
<input type='hidden' name='origin_path' value='{{ request.get_full_path }}'/>
{% crispy comment_form comment_form.helper %}
</form>
</div>
<div class='reply_comment'>
<form method="POST" action='{% url "comment_create" %}'>{% csrf_token %}
<input type='hidden' name='post_id' id='post_id' value='{% url "comment_create" %}'/>
<input type='hidden' name='origin_path' id='origin_path' value='{{ comment.get_origin }}'/>
<input type='hidden' name='parent_id' id='parent_id' value='{{ comment.id }}' />
{% crispy comment_form comment_form.helper %}
</form>
</div>
<script>
$(document).on('submit','.commentForAjax', function(e){
e.preventDefault(); …Run Code Online (Sandbox Code Playgroud) 我正在使用django嵌入式视频,因此当用户放置youtube链接视频时,我可以使用视频的缩略图
<img src="{{ my_video.thumbnail }}" class="img-rounded" alt="?" height="75" width="75"/>
Run Code Online (Sandbox Code Playgroud)
但是当用户插入不是youtube视频的链接时,我想插入默认图像.
目前这就是我所拥有的
{% if post.main_image %} //if post has main_image
<img src="{{post.get_image_url}}" class="img-rounded" alt="?" height="75" width="75"/>
{% elif post.url %} //if post has url
{% video post.video as my_video %}
{% if my_video %}//if that url is an link to video
<img src="{{ my_video.thumbnail }}" class="img-rounded" alt="?" height="75" width="75"/>
{% elif %} //if that url isn't a video
<img src="{{post.image}}" class="img-rounded" alt="? EBAGU" height="75" width="75"/>
{% endif %}
{% endvideo %} …Run Code Online (Sandbox Code Playgroud) 我有一个有效的通知系统.现在,当没有通知时,通知<span class='glyphicon glyphicon-inbox' aria-hidden="true"></span>就像stackoverflow一样出现.但我的愿望是,当有通知时,我希望盒子变成一个
<span class="badge badge-notify" style="red">notification count</span>
Run Code Online (Sandbox Code Playgroud)
再次就像堆栈溢出一样.
因此,如果count == 0,我尝试删除一个更改框形式的特定类,并在count不为零时添加类.我也试过设置设置间隔,但它不起作用.
你能帮我么?
下面是我在导航栏中的内容,我有通知框和徽章设置.
<li class="dropdown">
<a href="#" class="dropdown-toggle notification-toggle" data-toggle="dropdown" role="button" aria-expanded="false" id="button">
<span class='glyphicon glyphicon-inbox' aria-hidden="true"></span>
<span class="caret"></span>
<span class="badge badge-notify">notification count</span></a>
<ul class="dropdown-menu" role="menu" id='notification_dropdown'>
</ul>
</li>
Run Code Online (Sandbox Code Playgroud)
下面是我的ajax函数来显示通知
<script>
$(document).ready(function(){
$(".notification-toggle").click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "{% url 'get_notifications_ajax' %}",
data: {
csrfmiddlewaretoken: "{{ csrf_token }}",
},
success: function(data){
$("#notification_dropdown").html(' <li role="presentation" class="dropdown-header">alarm</li>');
var count = data.count
console.log(count)
if (count == 0) {
$("#notification_dropdown").removeClass('notification'); …Run Code Online (Sandbox Code Playgroud) 在我的base.html中,我{% include 'footer.html' %}和我将base.html扩展到我的每一页.但对于某些页面,我不希望页脚在那里.是否可以使用某个块关键字排除该页脚?
我已经弄清楚如何使用引导轮播,但问题是我想将我的精选故事呈现在轮播中。目前我有一个显示三张幻灯片的轮播,但我想做的是有特色故事而不是三张幻灯片。
<div class='carousel slide' id="myCarousel">
<ol class="carousel-indicators">
<li class="active" data-slide-to="0" data-target="#myCarousel"></li>
<li class="active" data-slide-to="1" data-target="#myCarousel"></li>
<li class="active" data-slide-to="2" data-target="#myCarousel"></li>
</ol>
<div class="carousel-inner">
<div class="item active" id="slide1">
<img src="http://i.imgur.com/SQ691ZO.jpg" >
<div class="carousel-caption">
<h4>hello</h4>
<p>hi you</p>
</div>
</div>
<div class="item" id="slide2">
<img src="http://i.imgur.com/zN4h51m.jpg" >
<div class="carousel-caption">
<h4>hello</h4>
<p>hi you</p>
</div>
</div>
<div class="item" id="slide3">
<img src="http://i.imgur.com/3ruWvoG.jpg">
<div class="carousel-caption">
<h4>hello</h4>
<p>hi you</p>
</div>
</div>
</div>
<a class="left carousel-control" data-slide="prev" href="#myCarousel"><span class="icon-prev"></span></a>
<a class="right carousel-control" data-slide="next" href="#myCarousel"><span class="icon-next"></span></a>
Run Code Online (Sandbox Code Playgroud)
所以这就是我尝试过的方法,但效果不太好。我有
{% for a in featuredStory …Run Code Online (Sandbox Code Playgroud) 我有评论系统工作(至少在后端工作).问题是每次用户提交评论时页面都会刷新.我为此写了一个ajax函数,但由于我是初学者,我期待得到一个错误而且我做了.我有500个内部错误.我不知道我做错了什么.在这里;我的代码
<div class='reply_comment'>
<form method="POST" action='{% url "comment_create" %}'>{% csrf_token %}
<input type='hidden' name='post_id' id='post_id' value='{% url "comment_create" %}'/>
<input type='hidden' name='origin_path' id='origin_path' value='{{ comment.get_origin }}'/>
<input type='hidden' name='parent_id' id='parent_id' value='{{ comment.id }}' />
{% crispy comment_form comment_form.helper %}
</form>
</div>
<script>
$(document).on('submit','.commentForAjax', function(e){
e.preventDefault();
$.ajax({
type:'POST',
url:'/comment/create',
data:{
post_id:$('#post_id').val(),
origin_path:$('origin_path').val(),
parent_id:$('#parent_id').val(),
csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
},
success:function(){
alert('it worked');
}
})
})
</script>
Run Code Online (Sandbox Code Playgroud)
我有这样的网址
url(r'^comment/create/$', 'comment_create_view', name='comment_create'),
Run Code Online (Sandbox Code Playgroud)
编辑:
我没有发布我的views.py,因为它很大,并且认为我写了一个错误的Ajax.我会发表我的观点
def comment_create_view(request):
if request.method == "POST" and request.user.is_authenticated():
parent_id = request.POST.get('parent_id')
post_id = …Run Code Online (Sandbox Code Playgroud)