小编Joe*_*Lin的帖子

PostgreSQL sql命令错误列'不存在'

dxdb=> \d dxtest_loadprofiletosale
                            Table "public.dxtest_loadprofiletosale"
   Column    |   Type   |                               Modifiers                               
-------------+----------+-----------------------------------------------------------------------
 id          | integer  | not null default nextval('dxtest_loadprofiletosale_id_seq'::regclass)
 TransDate   | date     | 
 IssueDate   | date     | 
 CustomerNum | smallint | not null
Indexes:
    "dxtest_loadprofiletosale_pkey" PRIMARY KEY, btree (id)

dxdb=> INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDate, CustomerNum) VALUES(1, '2015-03-04','2015-01-01',01);
ERROR:  column "transdate" of relation "dxtest_loadprofiletosale" does not exist
LINE 1: INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDat...
Run Code Online (Sandbox Code Playgroud)

对不起,我已经有了专栏"transdate",为什么它说不存在?

insert

5
推荐指数
1
解决办法
9281
查看次数

django 1.8不适用于CentOs 6.5服务器

Installing collected packages: Django
Successfully installed Django-1.8
[root@manage ~]# PYTHON
-bash: PYTHON: command not found
[root@manage ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/usr/lib/python2.6/site-packages/django/utils/version.py", line 7, in <module>
from django.utils.lru_cache import lru_cache
File "/usr/lib/python2.6/site-packages/django/utils/lru_cache.py", line 28 …
Run Code Online (Sandbox Code Playgroud)

python django centos6.5

3
推荐指数
1
解决办法
1796
查看次数

TypeError:makedirs()得到一个意外的关键字参数'exists_ok'

我正在使用"Lightweight Django"这本书学习Django.我正在使用Django 1.8.但是,我无法运行此代码.这是错误消息:

在此输入图像描述

工作树:

在此输入图像描述

build.py

import os
import shutil

from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.core.urlresolvers import reverse
from django.test.client import Client

def get_pages():
    for name in os.listdir(settings.SITE_PAGES_DIRECTORY):
        if name.endswith('.html'):
            yield name[:-5]

class Command(BaseCommand):
    help = 'Build static site output.'
    leave_locale_alone = True

    def handle(self, *args, **options):
        if os.path.exists(settings.SITE_OUTPUT_DIRECTORY):
            shutil.rmtree(settings.SITE_OUTPUT_DIRECTORY)
        os.mkdir(settings.SITE_OUTPUT_DIRECTORY)
        os.makedirs(settings.STATIC_ROOT, exists_ok=True)
        call_command('collectstatic', interactive=False, clear=True,verbosity=0)
        client = Client()
        for page in get_pages():
            url = reverse('page', kwargs={'slug': page})
            response = client.get(url)
            if page …
Run Code Online (Sandbox Code Playgroud)

python django

3
推荐指数
1
解决办法
1万
查看次数

将"data = urllib.parse.urlencode(values)"更改为python 2.7

每一个,我都要改变一些代码从python 3.*到2.7 ,,,但是,我只是不知道data = urllib.parse.urlencode(values)python 2.7中的代码是什么

python3.*

import urllib.parse
import urllib.request


def sendsms(phonenumber,textcontent):
    url = 'http://urls?'
    values = {'username' : 'hello',
              'password' : 'world',
              'dstaddr' : phonenumber ,
              'smbody': textcontent
               }

    data = urllib.parse.urlencode(values)
    data = data.encode('Big5') 
    req = urllib.request.Request(url, data)
    with urllib.request.urlopen(req) as response:
       the_page = response.read()
Run Code Online (Sandbox Code Playgroud)

python 2.7

from urlparse import urlparse
from urllib2 import urlopen
from urllib import urlencode

def sendsms(phonenumber,textcontent):
    url = 'http://urls?'
    values = {'username' : 'hello',
              'password' : 'world',
              'dstaddr' : phonenumber …
Run Code Online (Sandbox Code Playgroud)

urllib urllib2 python-2.7 python-3.x

2
推荐指数
1
解决办法
5511
查看次数

django模板帮助,颠倒

我正在尝试使用Django 1.8构建我的博客但是我不知道如何订购博客.看图像在此输入图像描述

我想在底部显示'最早',在顶部显示'最新'.这是我的

的index.html

{% extends 'layouts/base.html' %}
{% block title %}
Homepage - {{ block.super }}
{% endblock title %}
{% block content %}
<center>
{% for blog in blogs %}
<h2><a href="{% url 'blog_detail' slug=blog.slug %}">
{{ blog.name }}
</a></h2>
<p>{{ blog.description }}</p>
{% endfor %}
</center>
{% endblock content %}
Run Code Online (Sandbox Code Playgroud)

models.py

# -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone


class blog(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField()
    slug = models.SlugField(unique=True)
    date_time = …
Run Code Online (Sandbox Code Playgroud)

html python django

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

将 Django 与旧数据库集成不起作用

每个人:我正在尝试使用 django 1.8,mysql db 练习将 Django 与旧数据库集成,但没有成功,谁能告诉我发生了什么?非常感谢!我的 旧数据库

模型.py

# -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone


class blog(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField()
    slug = models.SlugField(unique=True)
    date_time = models.DateTimeField(auto_now_add = True)

    def __unicode__(self):
        return self.name



def get_image_path(instance, filename):
    return '/'.join(['blog_images', instance.bupimg.slug, filename])

class Upload(models.Model):
    bupimg = models.ForeignKey(blog, related_name="uploads")
    image = models.ImageField(upload_to=get_image_path)
Run Code Online (Sandbox Code Playgroud)

我只是按照这里文档

在我输入命令后 在此处输入图片说明

为什么我的 pidapp/models.py 显示的与旧数据库的 models.py 非常不同

pidapp/models.py

# This is an auto-generated Django model module.
# You'll have …
Run Code Online (Sandbox Code Playgroud)

python mysql django

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

django从数据库中搜索两个日期之间的日期时间

我正在尝试从数据库中搜索并列出两个日期之间的内容,但不知道该怎么做?这

模型.py

...
class ProductsTbl(models.Model):
    created = models.DateTimeField(editable=False)
...
Run Code Online (Sandbox Code Playgroud)

视图.py

def search(request):
    error = False
    if 'q1' and 'q2'in request.GET:
        q = request.GET['q1','q2']
        if not q:
            error = True
        else:
            books = ProductsTbl.objects.filter(created__range=q)
            return render(request, 'search_results.html',
                {'books': books, 'query': q})
    return render(request, 'search_form.html', {'error': error})
Run Code Online (Sandbox Code Playgroud)

我在这里查找了stackoverflow但不明白该怎么做

我应该在 models.py 中再添加一个 DateTimeField 来帮助搜索吗?

实际上我可以在 python manage.py shell 中做到这一点,但我怎样才能让它在网络上工作? 在此输入图像描述

我的

搜索表单.html

<form action="" method="get">
<table style="width:30%">
<tr>
<td><input type="text"  class="datepicker" name="q1"> </td>
<td style="width:5%"> between </td>
<td><input type="text"  class="datepicker" name="q2"></td>
<br> …
Run Code Online (Sandbox Code Playgroud)

django django-models django-views

0
推荐指数
1
解决办法
4629
查看次数