Django allauth urls produce 404 - python-3.x

So I'm trying to add all auth to existing DjangoCMS project and ran into this kinda weird issue. I added urls like this:
urlpatterns += i18n_patterns(
url(r'^admin/', admin.site.urls), # NOQA
url(r'^', include('cms.urls')),
path('account/', include('allauth.urls')), # <-- here )
But when I go to any url, say mydomain.com/en/account/login/ I get 404. In debug mode Django lists all sorts of patterns it tried to match, and among them - en/ account/ login/ [name='account_login'], concluding with
"The current path, /en/account/login/, didn't match any of these."
Moreover if I add {% url 'account_login' %} to a template, it works just fine, producing a link to mydomain.com/en/account/login/ which is still a 404 error. I have no idea where to even start debugging this :( Any suggestions?
Edit:
the contents of my allauth urls.py https://pastebin.com/PZDH6EDm
Django version 3.0.7

Replace the url with path:
urlpatterns += i18n_patterns[
path(r'^admin/', admin.site.urls), # NOQA
path(r'^', include('cms.urls')),
path('account/', include('allauth.urls')), # <-- here
]

Related

Template loader not looking at directories defined in DIRS

I'm trying to add a base template for use in different apps in my Django project. I've created a base.html file at "myapp/templates/base.html"
Here is the relevant info in my settings.py:
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'templates')],
'APP_DIRS': True,
'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',
],
},
},
]
When I try to load the view in my browser, I get a this error:
TemplateDoesNotExist at /home/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/home/
Django Version: 3.1.1
Exception Type: TemplateDoesNotExist
Exception Value:
base.html
Exception Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/template/backends/django.py, line 84, in reraise
Python Executable: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Python Version: 3.8.5
Python Path:
['/Users/jonmi/PycharmProjects/projects/grocery',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
Server time: Sun, 13 Dec 2020 01:43:02 +0000
As I understand it, the template loader should look in each of my installed_apps' template directories since APP_DIRS is set to True, and it should also look in any directory in the DIRS list. However, the template loader is only looking in the app directories (e.g. myapp/home/templates/home/base.html) and not in anything I add to the DIRS list.
I've tried changing whats in the DIRS list, including just trying to type out the path to base.html as a string myself, but it doesn't check anything I add to the list.
I've seen similar questions asked, but they are all for older versions of Django, and the solutions they've provided did not work for me. There are lots of people who have had the TemplateDoesNotExist error, but this is the question I've found most similar to mine: Django 1.8 ignores DIRS, cannot find templates
However, the solutions posted there did not help me, and the question is about a much older version of Django.
How can I get the template loader to look at what's in the DIRS list?
EDIT:
In trying to add some more info to my question, I figured out what was wrong. I had copy and pasted the TEMPLATES settings from another stackoverflow question into my settings.py, but I hadn't overwritten the old TEMPLATES settings, so they were getting switched back to my initial settings since my old settings were further down in my code.
If you're having this problem, the TEMPLATES settings in my question do indeed work properly.
Thanks to whoever read and commented.

308 redirect when using POST to upload a file to Flask application

I am building a small server application in Flask as part of a project I am working on. Part of the functionality is the ability to upload a small file of instructions for one of the key injectors to download. Each key injector has a name (''') which corresponds to a client and the file is uploaded to the server via a POST request.
The following listing is the Flask code.
#app.route('/upload/instructions/<ducky_name>/', methods = ['POST'])
def upload_Instruction(ducky_name):
file = request.files()
path = os.getcwd() +"/files/" + ducky_name
with open(path, "w") as f:
f.write(file)
print(f)
f.close()
return "Success"
And I am using this curl command to upload the file.
curl -X POST -d #test http://127.0.0.1:5000/upload/instructions/test1
I then get a 308 redirect, and the file is not uploaded. This is the first time I've dealt with uploading files as a POST in this way, and the also the first time I've used Flask.
Thanks
The URL you use in the curl request does not have the trailing slash as in your Flask route. In this case the framework redirects you to the route with slash (see the documentation entry). So just add the trailing slash:
curl -X POST -d #test http://127.0.0.1:5000/upload/instructions/test1/
Flask uses 308 HTTP response code instead of more common 301 to preserve the request method and body during redirect.
Flask use werkzeug.routing.Rule, which enable strict_slashes as default, visiting a branch URL without a trailing slash will redirect to the URL with a slash appended. Which cause response with 308 (Permanent Redirect).
If you want to support both routes:
/upload/instructions/<ducky_name>/
/upload/instructions/<ducky_name>
Just set app.route with strict_slashes=False, like this:
#app.route('/upload/instructions/<ducky_name>/', methods = ['POST'],
strict_slashes=False)
def upload_Instruction(ducky_name):
pass
refer: https://werkzeug.palletsprojects.com/en/1.0.x/routing/

10049: The requested address is not valid in its context.. Scrapy-Splash not reading URL correctly

I am trying to get the code to read in the web page using splash for a more complicated site, but I can't even get the code to run for this simple site location. I ran the docker and have the 8050 port mapped to 0.0.0.0 in my settings.py file. Any help would be greatly appreciated. Please provide version you used for any package as I fear this may be an issue.
I have tried numerous error fixes along the way. Changing the versions of Splash, Scrapy, and Twisted. Scrapy only works on Python 3.x with a newer version of Twisted, but Splash says incomparable with Twisted > 16.2. So I tried switching up the versioning some there with no fixes.
import scrapy
import scrapy_splash
class ExampleSpider(scrapy.Spider):
name = "test"
#allowed_domains = ["Monster.com"]
start_urls = [
'http://quotes.toscrape.com/page/1/'
]
def start_requests(self):
for url in self.start_urls:
yield scrapy_splash.SplashRequest(url, self.parse,
args={
'wait': 0.5,
},
endpoint='render.html',
)
def parse(self, response):
for quote in response.css('div.quote'):
print (quote.css('span.text::text').extract())
I should just receive the Quote Texts, ie. this is the same URL from the python documentation
There is nothing wrong with your code.
Your issue is this:
I have the 8050 port mapped to 0.0.0.0 in my settings.py file
The correct mapping in settings.py should be:
SPLASH_URL = http://localhost:8050
or
SPLASH_URL = http://127.0.0.1:8050

404 Not found error while using flask

I'm learning web development in python with the flask. The code doesn't show any error, but when I run it, the browser shows Error - 404 Not Found.
Code:
from flask import Flask, redirect, url_for
app = Flask(__name__)
#app.route('/admin/')
def hello_admin():
return 'Hello Admin'
#app.route('/guest/<guest>')
def hello_guest(guest):
return 'Hello %s as Guest' % guest
#app.route('/user/<name>')
def hello_user(name):
if name =='admin':
return redirect(url_for('hello_admin'))
else:
return redirect(url_for('hello_guest',guest = name))
if __name__ == '__main__':
app.run(debug=True)
Output in Chrome:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again
From Flask documentation:
An important detail to keep in mind is how Flask deals with trailing slashes. The idea is to keep each URL unique so the following rules apply:
If a rule ends with a slash and is requested without a slash by the user, the user is automatically redirected to the same page with a trailing slash attached.
If a rule does not end with a trailing slash and the user requests the page with a trailing slash, a 404 not found is raised
IMO, you may encounter the second situation.

Matching the root URL not working in Pyramid

According to the official documentation,
setting
config.add_route('root', '')
or
config.add_route('root', '/')
is supposed to take me to the root URL. I set this in my __init__.py.
I want my root to be at www.hello.com/language.
I have
config.include('.view', route_prefix='/language')
in my project's __init__.py
I also have a view configured
#view_config(route_name='root', renderer='template.jinja2')
in views.py
But, when I go to www.hello.com/language, I get a 404 not found.
What could be the issue?
It will be available at http://www.hello.com/language/. URL + trailing slash.
Perhaps you should look this issue https://github.com/Pylons/pyramid/issues/406
And for more understanding you can control your routes with command:
$ proutes development.ini
Name Pattern View Method
---- ------- ---- ------
__admin/sacrud_deform_static/ /admin/sacrud_deform_static/*subpath sacrud_deform:static/ *
__admin/deform_static/ /admin/deform_static/*subpath deform:static/ *
__admin/sa_static/ /admin/sa_static/*subpath pyramid_sacrud:static/ *
pyramid_sacrud_home /admin/ pyramid_sacrud.views.sa_home *
pyramid_sacrud_list /admin/{table}/ pyramid_sacrud.views.CRUD.List GET
pyramid_sacrud_create /admin/{table}/create/ pyramid_sacrud.views.CRUD.Add GET,POST
pyramid_sacrud_update /admin/{table}/update/*pk pyramid_sacrud.views.CRUD.Add GET,POST
pyramid_sacrud_delete /admin/{table}/delete/*pk pyramid_sacrud.views.CRUD.Delete GET
pyramid_sacrud_mass_action /admin/{table}/action/ pyramid_sacrud.views.CRUD.Action POST

Resources