小编ppt*_*ptt的帖子

PostgreSQL错误:无法连接到数据库template1:​​无法连接到服务器:没有这样的文件或目录

我需要创建数据库.

首先我运行:sudo su - postgres,然后:createdb test

我一直收到这个错误:

createdb: could not connect to database template1: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
Run Code Online (Sandbox Code Playgroud)

这是意料之外的,我从未遇到过psql的任何问题,但这次我没有得到什么问题.并且没有外部服务器,我在本地连接.

我在Ubuntu上运行.

postgresql ubuntu psql

14
推荐指数
2
解决办法
2万
查看次数

Django:如何检查用户名是否已存在

我不是Django的高级用户.我在网上看到了很多不同的方法,但它们都是针对修改过的模型,或者太复杂,我无法理解.我正在重复使用UserCreationForm我的MyRegistrationForm

class MyRegistrationForm(UserCreationForm):

    email = forms.EmailField(required=True)

    class Meta:
        model = User
        fields = ('username', 'email', 'password1', 'password2')

    def save(self, commit=True):
        user = super(MyRegistrationForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        user.set_password(self.cleaned_data["password1"])

        if commit:
            user.save()

        return user
Run Code Online (Sandbox Code Playgroud)

我很难理解或找到一种方法来检查用户输入的用户名是否已被使用.所以我只是用它来重定向到html,它说错误的用户名或密码不匹配:

def register_user(request):
    if request.method == 'POST':
        form = MyRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            return HttpResponseRedirect('/accounts/register_success')
        else:
            return render_to_response('invalid_reg.html')


    args = {}
    args.update(csrf(request))

    args['form'] = MyRegistrationForm()
    print args
    return render_to_response('register.html', args)
Run Code Online (Sandbox Code Playgroud)

这是我的注册模板(如果需要):

{% extends "base.html" %}

{% block content %}

<section>
<h2 style="text-align: center">Register</h2>
<form …
Run Code Online (Sandbox Code Playgroud)

python django validation registration username

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

django ×1

postgresql ×1

psql ×1

python ×1

registration ×1

ubuntu ×1

username ×1

validation ×1