I have been migrating a platform from django 1.11 to django 2 for the past week with no issues, up until today, when I tried to update my urls. I have these 3 lines of code:
1. url(r'^track/(?P<track_id>[0-9]+)/user/playlists', views.music),
2. path(r'track/<int:track_id>/user/playlists', views.music),
3. re_path(r'^track/(?P<track_id>[0-9]+)/user/playlists',views.music),
the original line that worked fine in django 1.11.
the new line that I created to replace Line 1. I removed the caret '^' and replaced the RegEx.
the line I am using right now because it is working fine.
My issue here is that my test fails when I use Line 2 but passes when I use Line 3.What could possible cause this behavior?
PS: The test that fails is just a test that passes 14 to the URL and checks the response. The response should be 200 but is 404 instead. In fact, I tried pdb inside the music method, but the test finished without stopping there, which means that it didn't even go in.
self.check_response('/track/%d/user/playlists/' % 14)
You're still using a regular expression in 2 because of the 'r'.
Make it like this:
path('track/<int:track_id>/user/playlists', views.music),
More details can be found here.
Related
Simply, I need to debug the admin.py file, but it doesn't give me the chance for this, so the error pops up directly without stopping at the break point or going line by line after it. So here I have a problem at line 14 related to the tuples because I have nested tuples without adding a comma after the nested tuple. enter image description here
I tried to render the page of the admin site to implement the method line by line, but the error happens directly
Sorry for this long question .
Don't put the point in function definition (a line with def command). It's not executed. Put it just below - it should stop just before executing that line.
I have installed Django-wiki in a fresh virtual Django install. My initial page comes up, the site allows for user registration. Everything looks well until I enter my first Root article.
I have kept it rudimentary with a title "Test" and the body just a simple "Hello" but when I save I get this error:
error at /
global flags not at the start of the expression at position 9
Request Method: GET
Request URL: http://xxxxxxx.preprod.xxxx:8000/
Django Version: 4.0.8
Exception Type: error
Exception Value:
global flags not at the start of the expression at position 9
Exception Location: C:\python\Lib\re_parser.py, line 841, in _parse
Python Executable: C:\daas_django_apps\env\Scripts\python.exe
Python Version: 3.11.0
Error during template rendering
In template C:\daas_django_apps\env\Lib\site-packages\wiki\templates\wiki\view.html, error at line 7
Line 7 is:
{% wiki_render article %}
I have tried checking all my configuration and it seems ok and matches Django-Wiki installation example. Tried changing user ownership of the article and creating a group for viewing but to no avail.
Any help would be appreciated.
Thank you!
Indeed, the use of inline global flags (eg: (?im)) in two regular expressions are now raising an exception, instead of a warning before 3.11 (https://github.com/python/cpython/issues/91222).
A fix has been merged on the main branch and it will be released soon if there are no other issues with 3.11.
See https://github.com/django-wiki/django-wiki/pull/1243 for more details.
I am using wkhtmltopdf on a Ubuntu server. The problem I have been facing is that negative big numbers break lines. I saw this thread: Prevent Breaking of Negative Numbers. My values are read directly from the database, and differently from this guy I don't add a hyphen.
Negative numbers:
Positive:
This is after I upgraded to version wkhtmltopdf 0.12.2.1 (with patched qt). On version 0.9.9, which I had been using I had no problem with PDF generation. I upgraded because in Django, Views which inherited the PDF class from django-wkhtmltopdf would give an error code 1, not generating PDF.
PDFs are generated through command line:
command = 'xvfb-run wkhtmltopdf --footer-right "[page]/[topage]" {s} {o}'.format(
s=html_file.name,
o=target.name
)
I tried to add --zoom 0.5 as a parameter to that command, but only made the PDF worse. Half of the text got cut out off the page and can't be read.
Try with replacing minus sign with − html entity.
I had the same issue. After much time of investigation, I discovered that you can solve the issue if you put min-width (css) in the column (td).
You must be sure that the min-width is enought for the value of td.
After that all work like a charm!
Good Look!
Just create a CSS rule, that says, the text should not wrap.
td.no-wrap {
white-space: nowrap;
}
Recently, we restructured a large site of one of our customers. This caused all the news-articels on that site to be on a different place. Problem is that the google cache is still showing them on the old location, leading to A LOT of 404 not founds ( its about 1400 news entries ).
Normally, a redirect using somewhat simple regex would be fine, but not only the path to the news did change, but also some parameters. Example:
Old Url:
http://www.customers-url.com/old/path/to/the/news/details/?tx_ttnews%5Btt_news%5D=67&cHash=a782f3027c4d00face6df122a76c38ed
How the new url should look like:
http://www.customers-url.com/new/path/to/news/?tx_news_pi1%5Bnews%5D=65
As you can see, the parameter D did change from 67 to 65 and the part of the URL before the ? did also change. Also, tx_ttnews has changed to tx_news and tt_news changed to news and the &cHash part did fall away completely.
I have the changed ids in a csv in the following format:
old_id, new_id
1,2
2,3
...etc...
Same goes the the changed url part before the ?. Since im not exactly an expert in using regex my question is:
Can this be done inside the .htaccess using RegEx ( not sure if it can even use a file as input)? How complicated is that? And how would such a regular expression look like?
Rather than trying to use .htaccess, it would be easier to manage and easier to code if you simply make a new page that responds on the old url (/old/path/to/the/news/details), then make that page build the new url and return a 301 to the browser with that new url.
I recently upgraded PHP to 5.4 and after adding some tweaks now the old osCommerce installation of a customer with lots of customisations is running again, but there is still a problem:
if you put an item in your cart the cart stays empty
How can I fix this?
Is there a certain php value I can set in php.ini so the session is working properly?
What I have tweaked so far:
Problem: all prices are 0 and there is no currency
Solution: adding !isset($currency) || in the paragraph `//
(see $currency not set in application_top under PHP 5.4 )
Problem: register_globals is REMOVED as of PHP 5.4.0
Solution: I simulated register_globals with this: https://serverfault.com/a/547285/128892
and I added this to includes/application_top.php:
// Bugfix PHP 5.4:
$HTTP_USER_AGENT=$_SERVER["HTTP_USER_AGENT"];
$HTTP_ACCEPT_LANGUAGE=$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$HTTP_HOST=$_SERVER["HTTP_HOST"];
$SERVER_NAME=$_SERVER["SERVER_NAME"];
$PHP_SELF=$_SERVER['PHP_SELF'];
$HTTP_GET_VARS=$_GET;
$HTTP_POST_VARS=$_POST;
register_globals();
comment out this line:
#ini_get('register_globals') or exit('FATAL ERROR: register_globals is disabled in php.ini, please enable it!');
also I had to correct some removed functions in includes/functions/sessions.php: session_unregister() and session_is_registered()
Problem remaining:
Items filled into the cart don't get added to the cart. seems like the session isn't known in the add_cart page.
I've had the same problem. Found by comparing my 2.2ms2 code with rc2a version.
In application_top change
$cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($_POST['products_id'], $_POST['id']))+$quantity, $_POST['id']);
to
$cart->add_cart($_POST['products_id'], $cart->get_quantity(tep_get_uprid($_POST['products_id'], $_POST['id']))+$_POST['quantity'], $_POST['id']);
I cound not fix this last problem, so after trying diffenent attempts I decided to take the effort and convert the shop with all its customisations into oscommerce 2.3 which still runs on PHP 5.4 (up to PHP 5.6).
Note that later, to get oscommerce running on php7 you'll need another fix for mysql functions to fix problems like Undefined function mysql_connect()