小编Nel*_*n M的帖子

在include()中使用命名空间时有关app_name的ImpropyConfiguredError

我正在尝试django.我在urls.py中使用了namespaceinclude()的一个参数.当我运行服务器并尝试浏览时,我收到此错误.

File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", line 39, in include
    'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
Run Code Online (Sandbox Code Playgroud)

这些是我的urls.py文件:

#project/urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^reviews/', include('reviews.urls', namespace='reviews')),
    url(r'^admin/', include(admin.site.urls)),
]
Run Code Online (Sandbox Code Playgroud)

#app/urls.py

from django.conf.urls import url …
Run Code Online (Sandbox Code Playgroud)

python django django-urls

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

“类型错误:需要一个类似字节的对象,而不是‘str’”。我怎样才能解决这个问题?

我试图运行这个亵渎检查器,但我收到一个“TypeError: a bytes-like object is required, not 'str'”。我怎样才能解决这个问题?

这是代码;

import urllib.request
import urllib.parse

def read_text():
    quotes = open("C:\Check Profanity\movie_quotes.txt")
    contents_of_file = quotes.read()
    print(contents_of_file)
    quotes.close()
    check_profanity(contents_of_file)

def check_profanity(text_to_check):
    encoded_text = urllib.parse.quote(text_to_check, 'utf-8')
    address = "http://www.wdylike.appspot.com/?q="+encoded_text
    connection = urllib.request.urlopen(address)
    output = connection.read()
    print(output)
    connection.close()
    if "true" in output:
        print("Profanity Alert!")
    elif "false" in output:
        print("This document has no curse words!")
    else:
        print("Could not scan the document properly.")

read_text()
Run Code Online (Sandbox Code Playgroud)

这是我尝试运行程序时抛出的错误。

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on …
Run Code Online (Sandbox Code Playgroud)

typeerror python-3.x

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

溢出错误:无法将“int”放入索引大小的整数中

为了确保密码总是在数据库中存储、散列和加盐,我决定使用一个描述符,当提供密码时,它会自动散列密码,例如 user.password = "jinja125"。

这是我的代码

from random import SystemRandom
from backports.pbkdf2 import pbkdf2_hmac, compare_digest

# ...snip...    

@password.setter
def password(self, value):
    # When a user is first created, give them a salt
    if self._salt is None:
        self._salt = bytes(SystemRandom().getrandbits(128))
    self._password = self._hash_password(value)
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行一些测试时,出现此错误。

File "C:\Users\User\flask-python\site-tracker\app\users\models.py", line 34, in password
    self._salt = bytes(random.SystemRandom().getrandbits(simple_bit_counts))
OverflowError: cannot fit 'int' into an index-sized integer
Run Code Online (Sandbox Code Playgroud)

我怎样才能最好地解决这个错误?

python flask flask-sqlalchemy

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