django-silk Page not found - django-silk

I did the install and I see the tables silk makes in my database so I know it is working but when I do the 127.0.0.1:8000/silk I get Page not found.
I did add the path('silk', include('silk.urls', namespace='silk')), to my urls file. I added 'silk.middleware.SilkyMiddleware', after 'django.contrib.sessions.middleware.SessionMiddleware'. Any ideas?

In my case it was the order of urlpatterns in url.py, I needed add path at the front instead of extending the list later on like:
urlpatterns = [
path("silk/", include("silk.urls", namespace="silk")),

Related

How to provide path for urlpatterns in Django3?

I'm trying to learn django but the instructor uses django 1.X.X.
So far, I've been able to update stuff to Django 3.X.X to get it working.
But I'm stuck now.
Specifically, in the below urlpatterns code:
urlpatterns = [
path('',views.SchoolListView.as_view(),name='list'),
path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail')
]
The first path works. The second one doesn't.
When I click on the url nothing happens. No error code, nothing.
I think there is a problem with the syntax? Is it different for Django3?
I checked the documentation and couldn't find anything wrong.
Thank you.
For example:
path ('',views.index , name='index')
For your code:
path('',views.SchoolListView,name='list')
The second pattern is part of djangos generic view .Generic views abstract common patterns to the point where you don’t even need to write Python code to write an app.
path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail')
Here pk represents primary key. Check if you have data with primary key you are giving in database.
Alternatively if u dont want to use generic method, you can use this
path('<int:school_id>/‘, views. SchoolListView, name='schoollist')
, where school_id(it can be other name depending on your model, verify it in db) should be the primary key in database created by django.

Getting No Urls to Fetch error on Nutch1.16

I am new to apache-nutch and want to crawl few questions on stackoverflow. My urls/seed.txt has following data:-
/questions/58763948/setting-a-list-item-is-converting-it-into-a-tuple
/questions/58763947/start-up-eclipse-an-error-has-occured-see-the-log-file
/questions/58763946/problem-with-the-proxy-using-zap-docker-image-gitlab
/questions/58763945/how-to-select-unique-random-data-based-on-percent-in-sql
/questions/58763943/probelm-with-using-filter-function-to-remove-missing-values-form-a-dataset
/questions/58763942/flutter-keep-data-in-textfield-after-setstate
/questions/58763941/are-receipts-generated-by-google-play-api-v2-and-the-latest-version-v3-compatibl
/questions/58763940/how-to-add-eventhandler-to-popupmenuitem-in-flutter
/questions/58763938/how-to-solve-electron-and-grpc-version-problem-in-angular-project
...
Is there any property which i can include in nutch-site.xml to add https://stackoverflow.com before every url in seed.txt. I don't want to change seed.txt since file is large
No, there is no such configuration property. It's possible to do this by adding the following rule to regex-normalize.xml:
<regex>
<pattern>^/</pattern>
<substitution>https://stackoverflow.com/</substitution>
</regex>
Also make sure that the plugin urlnormalizer-regex is included in the property plugin.includes.

django-viewflow - getting task URL without request

Knowing task instance is there a way to get the url of it? For example in the cookbook: https://github.com/viewflow/cookbook/blob/master/helloworld/demo/helloworld/flows.py - how do I get the url of assign task of approve flow_task?
I know there is flow_task.get_task_url(task, url_type='guess', namespace='', **kwargs), but the point is that from what I can see the namespace is usually fetched from self.request.resolver_match.namespace. That's not ideal - what if we are in other part of the app and we simply want to provide links to the tasks directly?
Same as with django reverse you need to pass a namespace to get an URL. In case of build-in viewflow frontend the namespace is viewflow:[app_label]:[flow_label] ex: "viewflow:helloworld:helloworld"
If you have the task object in a template, you can extract the url as follows:
Task Link
This could be added as a template filter if used often.
This is a dirty hack untill I understand how the namespaces work.
To get the url of a task all you need is the app_name(app_namespace), flow_namespace and flow_label.
The most challenging item here is the flow_namespace (if you have not used the frontend urls).
To resolve this, you could use a map borrowing from FlowListMixin's ns_map. Defining the flow_namespace for every flow in your project.
You then determine the flows namespace and url_name from the above.
ns_map = {'MyFlow':'flow_namespace', 'AnotherFlow':'flow_namespace2'}
# flow_namespace as defined in the urls.py
# e.g if you defined your flow urls as
# flow_urls = FlowViewSet(MyFlow).urls
# flow_urls2 = FLowViewSet(MyFlow2).urls
# urlpatterns = [url(r'flow_path/', include(flow_urls, name=flow_namespace)),
# url(r'flow_path2/', include(flow_urls2, name=flow_namespace2)),
# ]
# With this is included in the root_url as
# urlpatterns = [
# url(r'app/' include(app_urls, namespace='app_namespace')
#]
What you need is to reverse the flow like this
reverse('app_name:flow_namespace:flow_label', kwargs={'process_pk':ppk, 'task_pk':tpk})
flow_class_name = task.process.flow_class.__name__
flow_namespace = ns_map.get(flow_class_name)
app_name = task.process.flow_class.__module__.split('.')[0]
flow_label = task.flow_task.name
url_name = "{}:{}:{}".format(app_name, flow_label, url_name)
Then you can reverse your task url
url = reverse(url_name, kwargs={"task_pk", task.pk, "process_pk":task.flow_process.pk}
# If you know where you are you could use resolver match to determine
# the app namespace. Be Sure of this, see more of that [here][1]
NOTE: I am assuming that you namespaced your apps as app_name
If it is different you have to find alternatives to finding the app_names namespace but that should not be too difficult.

Prestashop Friendly URL's

I've been trying to create a second option of url rewrites to a product inside prestashop. In the standard Prestashop installation at the SEO & URL's section i've got the following products url build-up:
{category:/}{id}-{rewrite}-{ean13}.html
This creates the following products url:
https://www.example.com/{category-name}/{product-id}/{product-name}/{ean13}.html
What i would like to add is an option for various reasons to acces a products page through the following url build up:
ean/{ean13}.html
The result url would be something like the following example:
https://www.example.com/ean13/{ean13}.html
NOTE, ID is a standard required field of the url build up, this means that i can't use: "Just ajust the url build up" as an answer.
Is there a module, addon, or piece of code out there that would be able to generate these kind of structures?
I did find some "Remove ID's from pretty url's" modules but that doesn't give me the result i'm searching for. Only partially since it only removes the ID's.
It wouldn't be a problem if it's a redirect to the standard url build up as mentioned in the first {code} segment. I know i could write rewrite rules in my .htacces file but to do this for every product would be a lot of work so i was wondering if there is a more easy way of achieving this.
As always thanks in advance!
If you're fine with redirect to standard URL then the solution is quite easy with a module.
Create a module that uses hook moduleRoutes and configure a friendly URL to use module controller
Create a module front controller
Run a db query in your custom controller to check if a product with requested EAN exists
Redirect to product page if product exists, otherwise to 404 page or something
I assume you know how to write modules and controllers, so I won't write entire code just the relevant bits.
Hook moduleRoutes in module class.
In this hook you can configure a friendly URL for your custom controller.
public function hookModuleRoutes()
{
return [
'mymodulename-mycontrollername-root' => [
'rule' => 'ean13/{:ean13}.html',
'controller' => 'mycontrollername',
'keywords' => [
'ean13' => ['regexp' => '[0-9]+', 'param' => 'ean13']
],
'params' => [
'fc' => 'module',
'module' => 'mymodulename'
]
]
];
}
So visiting https://www.example.com/ean13/12345.html will run your module controller and a GET variable ean13 will have a value of 12345.
Then create mycontrollername module controller where you can use postProcess() method to check if EAN exists.
public function postProcess()
{
$query = new DbQuery();
$query->select('id_product')
->from('product_attribute', 'pa')
->where('pa.ean13 = ' . (int)Tools::getValue('ean13'))
$productId = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
if ($productId) {
Tools::redirect($this->context->link->getProductLink($productId));
}
Tools::redirect('pagenotfound');
}
In query we check in product_attribute table as product combinations can have their own EAN13 and you also want those EAN13's to redirect to product page.
The basics of this answer is most commonly used to replace core product search controller with a custom and SEO friendly one.

Can't access node-taxonomy.tpl.php through page-taxonomy-term.tpl in Drupal 6

I've been trying to customize taxonomy page template in my Drupal 6 site.
What I did was
created page-taxonomy-term.tpl.php
created node-taxonomy.tpl.php
Entered following code in template.php:
function templateNAME_preprocess_node(&$vars) {
if (arg(0) == 'taxonomy') {
$suggestions = array(
'node-taxonomy'
);
$vars['template_files'] = array_merge($vars['template_files'], $suggestions);
}
My Taxonomy page is picking up page-taxonomy-term.tpl.php correctly but it just doesn't pick up node-taxonomy.tpl.php and I tried just almost everything.
below few tips and attempts to do:
if you are working on subtheme, copy node.tpl.php from parent theme to the folder under subtheme (mandatory in drupal 6 themes).
try to check if the node-taxonomy suggestions is correctly added in
object $node. var_dump($node) inside the main node.tpl.php and check
if is present.
last tips: check the permission of the file tpl, maybe is not readable from the web server.

Resources