Django3 Include path/The include urls.py not showing up the templates - django-urls

I am pretty new to python Django; I am trying to figure out what exactly I am missing from the last few hours.
here is my code structure
url.py
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('signup', views.signupuser, name="signupuser"),
path ('', views.home, name='home'),
path ('socialcard', views.create_social_card, name='create_social_card'),
path ('dashboard/', include('dashboard.urls')),
]
Then I created another URL set in the dashboard app; here is the code.
From django.shortcuts import render
# Create your views here.
def dashboard(request):
home="dashboard"
return render(request, 'dashboard.html', {'home':home})
I am getting the following error,
TemplateDoesNotExist at /dashboard/
dashboard.html
I don't know what I am missing, I have added the templates folder in the app and have also added the subfolder dashboard. like this dashboard/templates/dashboard, and then there reside dashboard.html
When I add the template path as base.html, it loads up an empty page, doesn't display any error. So I don't know what exactly I am missing.

Well as all beginners do silly mistakes...I forgot to define my app in the setting.
I would advise all beginners that add the app in the setting as soon as you start an app.

Related

How to properly map my markdown content to dynamic URLs in Next.js?

I'd like to have the following URL structure:
URL
Role
/
markdown contents of /index.md
/about
markdown contents of /about.md
/cookies
markdown contents of /cookies.md
/privacy-policy
markdown contents of /privacy-policy.md
/category1
category1 index page
/category1/post1
markdown contents of /category1/post1.md
/category1/post2
markdown contents of /category1/post2.md
/category2
category2 index page
/category2/post1
markdown contents of /category2/post1.md
/category2/post2
markdown contents of /category2/post2.md
I'd like to avoid having to create separate .js files for my content in the root directory (so no /about.js, /cookies.js, etc), but if I try something like this...
pages/
index.js
[root_article_id].js
[category]/
index.js
[category_article_id].js
... then Next.js complains because it cannot decide when I request the URL /about whether if it should use [category]/index.js or [root_article_id].js, even though I feel the latter should be called first, and if it doesn't want to deal with the request (i.e. if there's no about.md in the root of my markdown directory), then it should fall back to [category]/index.js, which still could pass the request through to the 404 handler if [category].js spits it out.
What's the correct way of structuring Next.js files for this? Do I really need to have separate .js files for my markdown files in the root content directory?
What's the correct way of structuring Next.js files for this? Do I really need to have separate .js files for my markdown files in the root content directory?
This is the easiest way since you have to somehow tell nextjs what pages you want to be articles. However, if want to avoid doing it, you can do it with rewrites.
If you know all articles (or categories), this is what you need in your next.config.js:
module.exports = {
rewrites() {
return [
{
source: "/about",
destination: "/article/about",
},
{
source: "/cookies",
destination: "/article/cookies",
},
{
source: "/privacy-policy",
destination: "/article/privacy-policy",
},
];
},
};
And then make article/[root_article_id] page. Note that rewrite does not mean redirect. The page will be available in /about but nextjs will handle it like the request was to /article/about. This means that these pages will also be available from article/about, but this can probably be prevented if for some reason necessary.
Whether you should do rewrites for articles or categories depends on which one is dynamic. If neither one is really dynamic in a sense that you know all the possible values, you should pick the one with less possible values.
If both of categories and articles are dynamic, you need to do the rewrites with middleware (beta). In your middleware you get the req and you somehow need to decide if the requested url is an article or a category page. How this is done obviously depends on where and how you store your data.

Meteor Template.[name] is not defined

I'm restructuring my Meteor/Blaze app to keep related items in 'modules'. But I'm experiencing an issue with the first template.
My file structure is this:
/imports
/modules
index.js
/admin
index.js
methods.js
/client
adminPage.html
adminPage.js
The index.js files are loading fine. The adminPage.js is being imported alongside adminPage.html. But when I created Template.adminPage.onCreated(...) I got an error message, that I cannot call a function on undefined.
Calling console.log(Template) in the adminPage.js file returns this:
Section showing the admin page in console.log output.
But if I run console.log(Template.adminPage) I get undefined. I'm not sure what to look for next.
I found the issue. Instead of the correct:
import { Template } from 'meteor/templating';
I used
import Template from 'meteor/templating';
You are probably missing an import statement in /imports/modules/admin/client/adminPage.js. At the top of this file add the following:
import './adminPage.html';

How to use PrimeNG with Angular in aspnetcore-spa template

You know, I spend more time just trying to get things set up to work with Angular than I do actually developing with Angular. There must be an easier way... :(
Currently, I am using the aspnetcore-spa template, creating a project with the command "dotnet new angular" - this is version 1.0.3, which adds Angular 4.1.2 to the npm dependencies. This works great to get a project running quickly. But now I want to add PrimeNG to take advantage of their form controls. I have been struggling with this all day, and would love it if anyone could provide some assistance.
Here is what I have done in my current effort (the latest of many, starting fresh each time):
1) Added to the package.json file: "primeng": "4.1.0-rc.2"
2) Added 'primeng/primeng' to the webpack.config.vendor.js file's vendor collection.
3) Added the following to my test module (which is in turn referenced in app.module.shared.ts so I can route to it via my RouterModule):
import { FileUploadModule } from 'primeng/components/fileupload/fileupload';
And in the html for the module, in an attempt to use the file uploader control, I have (from their site - https://www.primefaces.org/primeng/#/fileupload):
<p-fileUpload name="myfile[]" url="./upload.php"></p-fileUpload>
4) ran "webpack --config webpack.config.vendor.js" from a command prompt at the root of the project folder, which completed with no errors.
Then I hit F5 to run the project, and I got this error:
Exception: Call to Node module failed with error: Error: Template parse errors:
'p-fileUpload' is not a known element:
1. If 'p-fileUpload' is an Angular component, then verify that it is part of this module.
2. If 'p-fileUpload' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message. (" type="button" (click)="onclick()" class="ui-button-info" label="Click Me">Click Me</button>-->
So, in an effort to comply, I added a reference to the ngprime module to the app.module.shared.ts file, like this (I don't really know how I should reference the module...):
import { FileUploadModule } from 'primeng/primeng';
But got the same exact error.
What am I missing???
Any help would be most appreciated.
I finally have this working, using the asp-prerender-module to get server-side rendering, and not having to rely on the asp-ng2-prerender-module (see my last comment). The trick, I found, was to reference the FileUploaderModule in the app.module.shared.ts file like this:
import { FileUploadModule } from 'primeng/components/fileupload/fileupload';
rather than like this:
import { FileUploadModule } from 'primeng/primeng';
The reason this matters is that the latter method of referencing will load all other components as well (see explanation here: https://www.primefaces.org/primeng/#/setup), and SOME of the PrimeNG components can not be rendered on the server due to DOM-related references (things like "window", which do not exist on the server). See the discussion here for more on this: https://github.com/primefaces/primeng/issues/1341
This change, combined with the other steps listed in my answer and, of course, actually referencing the directive in app.module (thank you #pankaj !) made everything work correctly at last. Only took me about 7 hours to figure it out. :(

Install fonts on angular 2 page

I have an Angular 2 application in which i wish to use wrapbootstrap. I do however have a problem with the fonts (bootstrap, font-awesome, google) as i do not know how to implement them.
When using the css file for wrapbootstrap is says it cannot find font awesome:
"Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8000/fonts/font-awesome/fontawesome-webfont.woff2?v=4.4.0"
I cannot make sense of this as i can see the missing file(s) in resources in the chrome console on that exact address.
The font files are currently in a folder vi the following relative path from the css (application.css) file using them:
Which fits the required path in the css file:
I hope someone out there can provide some guidance as i am lost.
Thanks in advance
Solved
the problem was apparently the location of my fonts folder.
my file structure are as follows:
and i had firstly added the fonts/ relative to where the application.css file was. It had to be located in the root of my app (src)
Adding fonts installed with package manager is quite often a task. For instance, using font-awesome or any other similar library is a typical task one will need.
For this purpose, you can go through the following steps:
In tools/config/project.config.ts:
...
export class ProjectConfig extends SeedConfig {
PROJECT_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'project');
FONTS_DEST = `${this.APP_DEST}/fonts`;
FONTS_SRC = [
'node_modules/bootstrap/dist/fonts/**'
];
...
Create a file tools/tasks/project/build.fonts.ts:
import * as gulp from 'gulp';
import Config from '../../config';
export = () => {
return gulp.src(Config.FONTS_SRC)
.pipe(gulp.dest(Config.FONTS_DEST));
};
In gulpfile.ts (or in seed.tasks.json for newer versions of the Seed)
// Build dev.
gulp.task('build.dev', done =>
runSequence('clean.dev',
'tslint',
'build.assets.dev',
'build.fonts', // Added task;
'build.js.dev',
'build.index.dev',
done));
// Build prod.
gulp.task('build.prod', done =>
runSequence('clean.prod',
'tslint',
'build.assets.prod',
'build.fonts', // Added task;
'build.html_css.prod',
'build.js.prod',
'build.bundles',
'build.bundles.app',
'build.index.prod',
done));
// Build test.
gulp.task('build.test', done =>
runSequence('clean.dev',
'tslint',
'build.assets.dev',
'build.fonts', // Added task;
'build.js.test',
'build.index.dev',
done));
src

Being unable to import module after succesfully adding reference, in asp.net IronPython

I'm adding a reference to a funciones.dll file using
clr.AddReferenceToFileAndPath() because I couldnt get it to work other way with this file and it succesfully does it. The file is named funciones.dll and it's in the bin folder. But when I do
from funciones import *
I get "no module named funciones"
since the funciones.dll file it's a funciones.py file compiled, shouldnt the module name only be named funciones and no any other name? isnt the name the problem and it's another? I dont know what other info could be relevant here but if there is any let me know
When doing the from x import * you need to put the namespace from the dll where x is.
So if you your code looks like
namespace Foo.Bar{
//code in here
}
your ironpython code would look like
import clr
clr.AddReferenceFromFileAndPath("/path/to/dll.dll")
from Foo.Bar import *
Solved by compiling the .py file with clr.CompileModules() instead of pyc.py . The module can be imported when you compile it that way (Thanks Dino)

Resources