[英]name 'privtopub' is not defined
My code looks like:我的代码看起来像:
from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages
from .models import Details
from bitcoin import *
import random
import bs4
import requests
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return redirect('/')
else:
messages.info(request, 'Invalid Credentials')
return redirect('login')
else:
return render(request, 'login.htm')
def register(request):
detail = Details()
bits = random.getrandbits(256)
bits_hex = hex(bits)
private_key = bits_hex[2:]
print(private_key)
# private_key = random_key()
public_key = privtopub(private_key)
address = pubtoaddr(public_key)
detail.private_key = private_key
detail.public_key = public_key
detail.address = address
But I get the error: name 'privtopub' is not defined
但我收到错误消息:
name 'privtopub' is not defined
I would start by importing bitcoin as:我首先将比特币导入为:
import bitcoin
rather than而不是
from bitcoin import *
The latter is not ideal programming practice and is said to "clutter the name space."后者不是理想的编程实践,据说会“使名称空间混乱”。
Then change your:然后改变你的:
public_key = privtopub(private_key)
to:到:
public_key = bitcoin.privtopub(private_key)
and see if your problem goes away.看看你的问题是否消失了。
Also, it looks like privtopub()
may be an alias for privkey_to_pubkey()
.此外,看起来
privtopub()
可能是privkey_to_pubkey()
() 的别名。 So maybe your version of bitcoin
is older and doesn't have the alias.因此,也许您的
bitcoin
版本较旧并且没有别名。 If so, you can also try just calling the method by the longer name.如果是这样,您也可以尝试使用较长的名称来调用该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.