I have problem reset password in django . My error is 'availabe Apps' key error - python-3.x

Firstly I call:
from django.contrib.auth import views as auth_views
After that I have set the url:
path('reset_password/',auth_views.PasswordResetView.as_view(),name='reset_password'),
When I run the url the key error raised.
Request Method: GET
Request URL: http://127.0.0.1:8000/user/reset_password/
Django Version: 3.1
Exception Type: KeyError
Exception Value:
'available_apps'
Exception Location: C:\Users\Syed Mithu\AppData\Local\Programs\Python\Python38\lib\site-packages\django\template\context.py, line 83, in __getitem__
Python Executable: C:\Users\Syed Mithu\AppData\Local\Programs\Python\Python38\python.exe
Python Version: 3.8.3
Python Path:
['F:\\12.05.2021\\Project\\Music_E-com',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib',
'C:\\Users\\Syed Mithu\\AppData\\Local\\Programs\\Python\\Python38',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Syed '
'Mithu\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\Pythonwin']
Server time: Thu, 20 May 2021 06:51:41 +0000

Related

Getting com_error when I interact with Django app

I'm getting an error when I try to use a Django app and Python 3.7.
com_error at /polls/
(-2147024891, 'Access is denied.', None, None)
Request Method: GET
Request URL: http://192.1.1.100:80/polls/
Django Version: 2.2.6
Exception Type: com_error
Exception Value:
(-2147024891, 'Access is denied.', None, None)
Exception Location: C:\Python64\Python37\lib\site-packages\appdirs.py in _get_win_folder_with_pywin32, line 481
Python Executable: C:\Python64\Python37\python.exe
Python Version: 3.7.4
Python Path:
['.',
'C:\\inetpub\\wwwroot\\Pounce',
'C:\\Python37\\python37.zip',
'C:\\Python37\\DLLs',
'C:\\Python37\\lib',
'C:\\Python37',
'C:\\Python37\\lib\\site-packages',
'C:\\Python37\\lib\\site-packages\\win32',
'C:\\Python37\\lib\\site-packages\\win32\\lib',
'C:\\Python37\\lib\\site-packages\\Pythonwin']
The app had been working fine over the past year. This is the first time I'm getting this error. I recently installed pypiwin32. Otherwise everything is the same.

Django Content Management System [duplicate]

My setup is Windows 10, Python 3.7, Apache 2.4/mod_wsgi. When I add this enctype="multipart/form-data" in my form (just by adding this attribute, only -- no files are attached to the form) I get this error when submitting:
Django Version: 1.8.5
Exception Type: RuntimeError
Exception Value: generator raised StopIteration
Exception Location: c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py in read, line 337
Python Executable: C:\Apache24\bin\httpd.exe
Python Version: 3.7.3
My Django code is this:
elif request.method == "POST":
rid = request.POST.get("recipe", "")
title = request.POST.get("title")
content = request.POST.get("content")
tag_names = request.POST.getlist("tags")
image = request.FILES.get("image")
if rid:
recipe = get_object_or_404(FoodRecipe, pk=rid)
else:
recipe = FoodRecipe.objects.create(title=title)
recipe.content = content
recipe.title = title
if image:
recipe.featured = image
for tn in tag_names:
tag, cr = Tag.objects.get_or_create(
name=tn
)
recipe.tags.add(tag)
recipe.save()
And this is full traceback:
Environment:
Request Method: POST
Request URL: http://192.168.1.250/recipes/add/
Django Version: 1.8.5
Python Version: 3.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'sekizai',
'sorl.thumbnail',
'recipes',
'guides',
'inbox',
'appdata',
'account',
'customer',
'core')
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',
'account.middleware.PasswordChangeMiddleware.PasswordChangeMiddleware')
Traceback:
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\core\handlers\base.py" in get_response
125. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\middleware\csrf.py" in process_view
174. request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\core\handlers\wsgi.py" in _get_post
137. self._load_post_and_files()
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\request.py" in _load_post_and_files
260. self._post, self._files = self.parse_file_upload(self.META, data)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\request.py" in parse_file_upload
225. return parser.parse()
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in parse
149. for item_type, meta_data, field_stream in Parser(stream, self._boundary):
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in __iter__
628. yield parse_boundary_stream(sub_stream, 1024)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in parse_boundary_stream
567. chunk = stream.read(max_header_size)
File "c:\users\holistic\envs\vitadmin\lib\site-packages\django\http\multipartparser.py" in read
337. out = b''.join(parts())
Exception Type: RuntimeError at /recipes/add/
Exception Value: generator raised StopIteration
Any ideas what is going wrong?
PS: Same django application worked fine in Linux/Nginx/Gunicorn/Python2.7 setup. So, I guess it must some misconfiguration between Django/Python/Apache.
Your Django is very old and you need to update. This is a Python 3.7 compatibility problem that the Django devs already fixed four years ago, back when it was just a PendingDeprecationWarning on Python 3.5.
In fact, you are on the very last Django version that doesn't have the fix. Even 1.8.6 has the fix.

TypeError: 'module' object is not callable Django 3 render function

I am just making a simple hello world page in my Django 3 Application I am getting error
TypeError: 'module' object is not callable
Here is the error
TypeError at /
'module' object is not callable
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 3.0.11
Exception Type: TypeError
Exception Value:
'module' object is not callable
Exception Location: C:\Users\admin\AppData\Roaming\Python\Python37\site- packages\django\template\context.py in bind_template, line 246
Python Executable: C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python37_64\python.exe
Python Version: 3.7.8
Python Path:
['C:\\Users\\admin\\Repositories\\django-docker\\django-portal-base\\app',
'C:\\Program Files (x86)\\Microsoft Visual '
'Studio\\Shared\\Python37_64\\python37.zip',
'C:\\Program Files (x86)\\Microsoft Visual
Studio\\Shared\\Python37_64\\DLLs',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\lib',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64',
'C:\\Users\\admin\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Program Files (x86)\\Microsoft Visual '
'Studio\\Shared\\Python37_64\\lib\\site-packages']
Server time: Thu, 14 Jan 2021 19:15:32 +0000
It was working before but suddenly not working now. Here is my views.py
from django.shortcuts import render
# from django.http import HttpResponse
# from django.template import RequestContext, loader
# from django.template import Context
def index(request):
"""Placeholder index view"""
print('XXXX')
return render(request, 'hello_world/index.html')
#return HttpResponse('Hello, World!')
def test(request):
context = {'foo': 'bar'}
return render(request, 'hello_world/index.html', context)
The error is in line return render(request, 'hello_world/index.html') but when I change it to return HttpResponse('Hello, World!') it works fine.
My html file is very simple index.html
<h3> MY DJANGO APP</h3>
The html file is also in the correct folder templates/hello_world/index.html
settings
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.contrib.sessions'
],
},
},
]
django.contrib.sessions is not a callable object, hence it's not a valid context processor.
In fact, it's an app and, so, it should be in your INSTALLED_APPS list, not in the TEMPALTES context_processors list. Removing it from there should fix this issue.
Why is this happening?
The exception mentions that it is happening in django/template/context.py line 246 (in Django v3.0.11). If you see the source code at line 246, you can see that at this line Django is running the registered template context processors. Since, django.contrib.sessions is not a callable object, but a module, you get this exception message: 'module' object is not callable.

Display query-set results on a Django template without using a django model

AttributeError at /Blog/mycustomsql
module 'django.http.request' has no attribute 'META'
Request Method: GET
Request URL: http://127.0.0.1:8000/Blog/mycustomsql
Django Version: 2.1.5
Exception Type: AttributeError
Exception Value:
module 'django.http.request' has no attribute 'META'
Exception Location: C:\Users\c822208\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\context_processors.py in debug, line 40
Python Executable: C:\Users\c822208\AppData\Local\Programs\Python\Python37\python.exe
Python Version: 3.7.3
Python Path:
['C:\cygwin64\home\c822208\django\hr',
'C:\Users\c822208\AppData\Local\Programs\Python\Python37\python37.zip',
'C:\Users\c822208\AppData\Local\Programs\Python\Python37\DLLs',
'C:\Users\c822208\AppData\Local\Programs\Python\Python37\lib',
'C:\Users\c822208\AppData\Local\Programs\Python\Python37',
'C:\Users\c822208\AppData\Local\Programs\Python\Python37\lib\site-packages']
Server time: Wed, 9 Oct 2019 08:58:49 +0000
def mycustomsql(self):
import cx_Oracle
conn_string = cx_Oracle.connect('hr/passwd#127.0.0.1/xe')
cursor1=conn_string.cursor()
cursor2=conn_string.cursor()
cursor1.execute("SELECT p.name,p.value FROM v$parameter p ORDER BY p.name")
results1 = cursor1.fetchall()
cursor2.execute("SELECT p.name,p.value FROM v_param p ORDER BY p.name")
results2 = cursor2.fetchall()
for index in range(0,len(results1)):
if results2[index] == results1[index]:
# print ('Found')
continue
rs= (results1[index]," : ",results2[index])
# return HttpResponse(rs) -- this is giving me one row instead of 2
context = {
"object_list": rs
}
return render(request, "Blog/param.html", context)
python python_tut/query.py
localhost/xe - ('shared_pool_size', '0') : localhost/xe - ('shared_pool_size', '5')
localhost/xe - ('streams_pool_size', '0') : localhost/xe - ('streams_pool_size', '8')

Abnormal behavior of python package eve

I have installed the eve package on my windows machine but every time I shutdown the machine and try to load the eve package I get module not found error.
On re-installation attempt(Btw I used the latest pip version to install), I get
from eve import Eve
app=Eve()
app.run()
The error points to the second line.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-79-46d1b24866c8> in <module>()
30 # host = '127.0.0.1'
31
---> 32 app = Eve()
33 # app.run()
34
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eve\flaskapp.py in __init__(self, import_name, settings, validator, data, auth, redis, url_converters, json_encoder, media, **kwargs)
158 self.settings = settings
159
--> 160 self.load_config()
161 self.validate_domain_struct()
162
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eve\flaskapp.py in load_config(self)
275
276 try:
--> 277 self.config.from_pyfile(pyfile)
278 except:
279 raise
~\AppData\Local\Continuum\anaconda3\lib\site-packages\flask\config.py in from_pyfile(self, filename, silent)
128 try:
129 with open(filename, mode='rb') as config_file:
--> 130 exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
131 except IOError as e:
132 if silent and e.errno in (
~\AppData\Local\Continuum\anaconda3\lib\site-packages\bokeh\settings.py in <module>()
9 from os.path import join, abspath, isdir
10
---> 11 from .util.paths import ROOT_DIR, bokehjsdir
12
13
ModuleNotFoundError: No module named 'config'
Moreover, I find that there is no folder "lib" but "Lib". If this is the problem how do I rectify it?
However, the code below works but runs for microsecs, not like running a back-end server with api's:
from eve import Eve
app=Eve
app.run
The settings.py file:
# Let's just use the local mongod instance. Edit as needed.
# Please note that MONGO_HOST and MONGO_PORT could very well be left
# out as they already default to a bare bones local 'mongod' instance.
MONGO_HOST = 'localhost'
MONGO_PORT = 27017
MONGO_DBNAME = 'apitest'
# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide
# read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
# individual items (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']
people = {
# 'title' tag used in item links.
'item_title': 'person',
# by default the standard item entry point is defined as
# '/people/<ObjectId>/'. We leave it untouched, and we also enable an
# additional read-only entry point. This way consumers can also perform GET
# requests at '/people/<lastname>/'.
'additional_lookup': {
'url': 'regex("[\w]+")',
'field': 'lastname'
},
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'POST'],
# Schema definition, based on Cerberus grammar. Check the Cerberus project
# (https://github.com/pyeve/cerberus) for details.
'schema': {
'firstname': {
'type': 'string',
'minlength': 1,
'maxlength': 10,
},
'lastname': {
'type': 'string',
'minlength': 1,
'maxlength': 15,
'required': True,
# talk about hard constraints! For the purpose of the demo
# 'lastname' is an API entry-point, so we need it to be unique.
'unique': True,
},
# 'role' is a list, and can only contain values from 'allowed'.
'role': {
'type': 'list',
'allowed': ["author", "contributor", "copy"],
},
# An embedded 'strongly-typed' dictionary.
'location': {
'type': 'dict',
'schema': {
'address': {'type': 'string'},
'city': {'type': 'string'}
},
},
'born': {
'type': 'datetime',
},
}
}
DOMAIN = {
'people': people,
}
So, What could be the solution to this problem?
Any help is appreciated.
I don't have this issue after a quick test. Let me share with you all steps and let me know anything is different.
1) Enter Anaconda Prompt
2) conda create -n eswar python=3.6
3) conda activate eswar
4) pip install eve
5) python
5.1) import eve
5.2) exit()
6) shutdown windows machine
7) restart windows machine
8) enter anaconda prompt
9) conda activate eswar
10) python
11) from eve import Eve
12) everything looks fine.
did you forget to activate your env after restart?

Resources