python custom password hasher error - python

hye . i cannot import my new custom password hasher and i still cannot figure it out why .
the error :
ImportError at /admin/
No module named 'honeywordHasher.hashers.MyHoneywordHasherdjango'; 'honeywordHasher.hashers' is not a package
i already did install honeywordHasher in INSTALLED_APPS and i have the init.py inside the honeywordHasher file.
directory :
C:.
├───checkout
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ └───__pycache__
├───contact
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ └───__pycache__
├───custom_user
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───honeywordHasher
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───profiles
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ │ └───accounts
│ └───__pycache__
├───register
│ ├───migrations
│ ├───templates
│ │ └───accounts
│ └───__pycache__
├───sqlite
├───tryFOUR
│ └───__pycache__
└───__pycache__
settings.py :
PASSWORD_HASHERS = [
'honeywordHasher.hashers.MyHoneywordHasher'
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
]
i already create hashers.py and also the honeyword generation in honeywordgen.py . i still get this error . can someone help me ?

You have missed out the comma after your custom hasher. It should be:
'honeywordHasher.hashers.MyHoneywordHasher',
Without the comma, Python concatenates the string with the one on the next line to form 'honeywordHasher.hashers.MyHoneywordHasherdjango.contrib.auth.hashers.PBKDF2PasswordHasher', which causes the import error.

Related

ModuleNotFoundError: No module named 'api' (heroku)

tree
├───pzApi
│ │ asgi.py
│ │ db.sqlite3
│ │ manage.py
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ └───api
│ │ apps.py
│ │ funcs.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
Procfile
release: python pzApi/manage.py migrate
web: gunicorn --bind 127.0.0.1:8000 pzApi.wsgi:application
I'm still trying to deploy this web app and after fixing the wsgi.py not found error by putting it in the same dir as manage.py, now I have another problem where the 'api' folder is not being found, any help is appreciated!

Importing from different directories in Python

I'm trying to build a very simple Web Scraper that scrapes from popular Job Boards and posts the jobs in a simple Django website.
In my Scrapy spider, I am trying to create a Django model object for every job scraped. But I'm having trouble importing the model in my Scrapy spider file.
This is my folder structure:
F:.
│ db.sqlite3
│ manage.py
│
├───jobs_board
│ asgi.py
│ settings.py
│ urls.py
│ wsgi.py
│ __init__.py
│
├───main
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ 0001_initial.py
│ │ __init__.py
│ │
│ └───templates
│ └───main
│ home.html
│
└───scraper
│ scrapy.cfg
│ t.py
│ testing.md
│
└───scraper
│ items.py
│ middlewares.py
│ pipelines.py
│ settings.py
│ __init__.py
│
└───spiders
indeed.py
__init__.py
What I want to do is, if I run the spider "indeed.py", I want it to be able to import the main/models.py file. How would I achieve this?
Thank you for your help! :)

Converting my project to a package with modules

I am converting my python project into packages, with sub-packages, with modules. The tree structure is as shown below (sorry for the long tree). When I run run.py, it imports MyEnvironment.environment which in turn has statements like from station import Station. It is at this stage that I get an error saying ModuleNotFoundError: No module named 'station'. I am not able to figure why this is happening. Note that it work when I do sys.append('.\Environment'), but it should work without it since I already added __init__.py. Could someone help here?
C:.
├───.vscode
│ settings.json
│
└───DRLOD-Package
│ run.py
│ __init__.py
│
├───MyEnvironment
│ │ agv.py
│ │ environment.py
│ │ job.py
│ │ job_queue.py
│ │ parent_area.py
│ │ path_finding.py
│ │ pdnode.py
│ │ policy.py
│ │ request.py
│ │ station.py
│ │ stats.py
│ │ test.py
│ │ __init__.py
```
In environment.py use from .station import Station

i want to import all classes from a model.py which is not in my app modules in Django

in Django, my model.py is out of my App modules I want to import all the classes from that model.py to all modules. I searched a lot I didn't get anything can anyone help me
here is my directory
C:
│ manage.py
│ **models.py**
│ mysqlclient-1.4.6-cp39-cp39-win_amd64.whl
│
│
├───myshop
│ │ asgi.py
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
├───products
│ │ admin.py
│ │ apps.py
│ │ tests.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ │ __init__.py

Django unable to show webpage

1Trying to use Django 1.10 to create a file upload system (similar to this example here. My main problem is, no matter how hard I try, Django is unable to show my webpage (404 error). I have no idea why. I'm following the 1.9 example and it should be working, as far as I can tell. I've attached the error and my data tree
[D:.
│ db.sqlite3
│ manage.py
│
├───.idea
│ courseworkupload.iml
│ misc.xml
│ modules.xml
│ workspace.xml
│
├───courseworkupload
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│ │ __init__.py
│ │
│ └───__pycache__
│ settings.cpython-35.pyc
│ urls.cpython-35.pyc
│ wsgi.cpython-35.pyc
│ __init__.cpython-35.pyc
│
├───upload
│ │ admin.py
│ │ apps.py
│ │ forms.py
│ │ models.py
│ │ tests.py
│ │ urls.py
│ │ views.py
│ │ __init__.py
│ │
│ ├───migrations
│ │ │ 0001_initial.py
│ │ │ __init__.py
│ │ │
│ │ └───__pycache__
│ │ 0001_initial.cpython-35.pyc
│ │ __init__.cpython-35.pyc
│ │
│ ├───templates
│ │ Final.html
│ │ upload.html
│ │
│ ├───uploadedfiles
│ └───__pycache__
│ admin.cpython-35.pyc
│ forms.cpython-35.pyc
│ models.cpython-35.pyc
│ urls.cpython-35.pyc
│ views.cpython-35.pyc
│ __init__.cpython-35.pyc
│
├───Uploadedfiles
└───__pycache__
manage.cpython-35.pyc][2]
Views.py below
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.shortcuts import render
from django.core.urlresolvers import reverse
from .forms import docfieldform
from .models import Document
def upload(request):
if request.method == 'POST':
form = docfieldForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document (docfile=request.FILES['newfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('upload'))
else:
form = docfieldform()
return render( request,'Final.html',)
You need to remove the .html in your URL conf so that it becomes url(r'^upload/$', upload, name='upload'). So if your browser url is http://127.0.0.1:8000/upload/upload/ it should go to the upload view.
To display content in upload.html replace render(request, 'Final.html') with render(request, 'upload.html') in your upload view

Categories

Resources