NoReverseMatch at /portal - python

I am still trying to find out why the same line of code works in Apache 2.2.22 with mod_wsgi and causes an error with any other version such as 2.2.25 and 2.4. When I run the python/django app under 2.2.22, no errors, no complaints, no loss of functionality. When I change the Apache to be 2.2.25 (or 2.4) I get the following error messages from Django ...
Request URL: http://127.0.0.1/portal/
Django Version: 1.5.1
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'account_index' with arguments '()' and keyword arguments '{}' not found.
Exception Location: C:\Python27\lib\site-packages\django\template\defaulttags.py in render, line 424
Python Executable: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe
Referring to these lines ...
48 {% if user.is_superuser %}
49 <li><a tabindex="-1" href="{% url 'account_index' %}">Browse</a></li>
50 {% else %}
This is the only piece that causes an error and I have no explanation as to why. The link next to it is exactly the same and causes no errors. I have checked the Apache logs, there is no complaint about wsgi failures. The Django error message gives me no more info than above. I am very confused about this as going to the html template file and removing line #49 eliminates the error (but also the dropdown menu).
* Looking at related posts about similar errors gave me the idea that this line from account.urls.py might be the problem, can anyone comment on this?
url(r'^/?$', 'account.views.account_index', name='account_index'),

Related

How to use "truncatechars" in flask? ( Error : No filter named 'truncatechars'. )

I am trying to use truncatechars in flask. When previously I used truncatechars in django the following code worked
The code (Django):
<div class="preview">{{post.content |safe| truncatechars:500}}</div>
But when I use truncatechars in flask it throws an error saying jinja2.exceptions.TemplateAssertionError: No filter named 'truncatechars_html'.
The code (Flask):
<div class="preview">{{post.content |safe| truncatechars(500)}}</div>
When I used ":" instead of brackets "()" it throwed an error saying jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':'
In Jinja2 this filter is called truncate:
<div class="preview">{{ post.content|safe|truncate(500) }}</div>

React / Apollo: Displaying Error of GraphQL mutation (useMutation hook)

I am having a hard time trying to figure out why I can't show the error of my mutation.
I have implemented error codes in my mutation:
if location_lat < 0.1 and location_lon < 0.1:
raise GraphQLError('E_CF_002')
now on the client-side, I call the following mutation, which is called onSubmit of a form and I purposefully trigger the error.
const [
createEvent,
{ data: createData, loading: createLoading, error: createError}
] = useMutation(CREATE_EVENT);
The error code is successfully returned as seen in my network tab:
{"errors": [{"message": "E_CF_002", "locations": [{"line":
However, when I try to show the error in a dialogue box
{createError && (
<div>
<Dialog open={openDialog} onClose={handleClose}>
<h3>Sorry, an error occured while creating the event.</h3>
<h3>Plese try again later. {JSON.stringify(createError)} </h3>
<DialogActions>
<Button onClick={handleClose} color="primary">
Okay
</Button>
</DialogActions>
</Dialog>
</div>
)}
I only see:
Sorry, an error occured while creating the event.
Plese try again later. {}
Can anyone help me understand why my error variable does not hold the message etc.?
I first tried directly printing createError.message or createError[0].message or even createError.errors and even createError.errors[0] however later on I saw that even the entire JSON is empty by printing JSON.stringify(createError).
I haven't been able to find this specific issue (or it's solution) on StackOverflow or elsewhere.
Thank you in advance!

django-user-accounts package does not load the account/signup.html template

I am trying to use the django-user-accounts package from pinax. I am completely new to django, and I get stuck at some point, I've been struggling for hours but I still cannot display the account/signup page.
So, I have the following line in my urls.py:
url(r"^account/", include("account.urls")),
Then, I went to check in the urls.py of the account package, and
it countains this line.
url(r"^signup/$", SignupView.as_view(), name="account_signup"),
So, when I give the address: 127.0.0.1:8000/account/signup/ in my browser, I think that django should give back the SignupView. But I don't really know what the "as_view()" function does. Usually the second argument of url() should be a function that returns a HTMLResponse. So I went to see in the views.py of the account package: The class SignupView has an attribute
template_name = "account/signup.html"
I would expect the HTMLResponse returned by SignupView.as_view() to be using this template but it doesnt. Instead, I got this error:
TypeError at /
'str' object is not callable
Request Method: GET Request URL: http://127.0.0.1:8000/ Django
Version: 1.6.1 Exception Type: TypeError Exception Value:
'str' object is not callable
Exception Location:
/usr/lib/python2.7/dist-packages/django/core/handlers/base.py in
get_response, line 112 Python Executable: /usr/bin/python Python
Version: 2.7.6
Note that this is just the default behaviour of django-user-accounts, I have not modified anything. So I guess that I am missing a dependency or something, but I cannot interprete the error message. By the way, the returned error is exaclty the same as when I give this address in the browser 127.0.0.1:8000/. Here I expect to receive an error because I have no home page yet, but still, why does the SignupView try to get the html of the root page ???
I am stuck here and I have no idea how I can try to debug this. Any hints would be more than welcome.
So, the problem has been solved thanks to a comment of Bilou06, the problem was actually caused by another line in the urls.py of the project, because the root of the project was pointing to an indexView that did not exist.

Send parameters using URL syntax

I'm trying to use the audio player Timeside in Django 1.5. JavaScript function that handles loading the player receives this set of parameters,
loadplayer.js
loadPlayer function (analizerUrl, soundUrl, soundImgSize, itemId, visualizers, CurrentUserName, isStaffOrSuperuser)
In my template is the following script that handles launch
{% If item.file %}
loadPlayer('{% url 'item-analyze-xml' item.public_id %}',
"{% url 'item-export' item.public_id,"mp3" %}", undefined, '{{item.id}}', visualizers,
CURRENT_USER_NAME, //undefined if !user.is_authenticated
true); //true because superuser
{% Endif%}
URLs are configured as follows
url(r'^archives/items/download/(?P<public_id>[A-Za-z0-9._-]+)\.(?P<extension>'
+ export_extensions + ')$',
item_view.item_export,
name="item-export"),
url(r'^archives/items/(?P<public_id>[A-Za-z0-9._-]+)/analyze/xml/$',
item_view.item_analyze_xml,
name="item-analyze-xml"),
This worked in Django 1.4, attempt to update for be used in version 1.5. The problem is that I can not send the parameter MP3 here
"{% url 'item-export' item.public_id,"mp3" %}",
the view item_export is like this:
def item_export(self, request, public_id, extension):
When the player loads I get the following error:
Could not parse the remainder: ',' from 'pista.public_id,'
Which is the correct syntax for this on Django 1.5?
Using the name and equal solved this step
{% url 'item-export' public_id=item.public_id extension="mp3" %}
Seems like it is working but I have a new error:
NoReverseMatch at /pista/1/
Reverse for 'item-analyze-xml' with arguments '()' and keyword arguments '{u'public_id': ''}' not found.
I do not want to answer my own question but I've been searching and trying a lot and I found the solution.
{% Url 'impromusic-item-export' item.id 'mp3'%}
The first quotes refer to the name of the url(everybody know), item.id can be variable depends on the object, but if I write it in quotes it will be a string of characters wich not accept any value beyond which we assign.
That's my conclusion after 5 hours of searching but I can be wrong :) hope u understand me

Using '#notfound_view_config' in Pyramid with 'renderer'

I'm unable to get my specified template to render when using #notfound_view_config as described in Pyramid Docs - Using Hooks.
views.py:
#notfound_view_config(renderer='templates/notfound.pt')
def notfound(request):
return Response('Not Found, dude', status='404 Not Found')
templates/notfound.pt:
<html xmlns="http://www.w3.org/1999/xhtml"
metal:use-macro="base">
<tal:block metal:fill-slot="content">
<!-- Example row of columns -->
<div class="row">
<div class="span12">
<h1>Error:</h1>
<p>Uh, oh... you snagged an error:</p>
<pre>"${request}"</pre>
<p>You can return to the homepage if you wish.</p>
</div>
</div>
</tal:block>
</html>
When hitting a page that doesn't exist, I see the message "Not Found, dude" on a blank page, but I expected to see my template with "Uh, oh... you snagged an error!" followed by the request information.
I suspect I'm reading this wrong:
The notfound_view_config constructor accepts most of the same
arguments as the constructor of pyramid.view.view_config. It can be
used in the same places, and behaves in largely the same way, except
it always registers a not found exception view instead of a ‘normal’
view.
On one hand, it seems like I should be able to specify 'renderer' as a parameter since it's supported in pryamid.view.view_config. On the other hand, it sounds like it's always loading the [not found exception view][3], regarless of the 'renderer' option.
Really, my ultimate question (and goal) is, how do I display/render my template whenever a page is not found?
The renderer-view relationship is always the same in Pyramid. If you return a Response object, then your declared renderer is bypassed. This allows you to do things like if submitted: return HTTPFound(location=...) else: return {}. If you'd like to affect the response object and still use your renderer, then return the required dict and mutate request.response, the response object that is used for all renderers.
#notfound_view_config(renderer='templates/notfound.pt')
def notfound(request):
request.response.status = 404
return {}

Categories

Resources