I am trying to get a template to be rendered under my templates folder. I believe I set my views correct, URL settings, and settings for to render the view. However, I keep getting the same error, where the template cannot be found. I keep thinking its a path issue but cant put my finger on the issue. I added my screens of different views of my code.
# In newword/newword/newword/views.py
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {})
# In newword/newword/newword/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ 'templates/home.html'],
'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',
],
},
},
]
# In newword/newword/newword/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),`enter code here`
]
# In newword/newword/newword/templates/home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Home</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body></body>
</html>
# Error Output
TemplateDoesNotExist at /
home.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.1.5
Exception Type: TemplateDoesNotExist
Exception Value:
home.html
Exception Location: /usr/local/lib/python3.7/site-packages/django/template/loader.py in get_template, line 19
Python Executable: /usr/local/opt/python/bin/python3.7
Python Version: 3.7.2
Python Path:
['/Users/robertromulus/pythonProjects/newword/newword',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
'/Users/robertromulus/Library/Python/3.7/lib/python/site-packages',
'/usr/local/lib/python3.7/site-packages']
Server time: Mon, 7 Jan 2019 03:02:48 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /Users/robertromulus/pythonProjects/newword/newword/templates/home.html/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/admin/templates/home.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.7/site-packages/django/contrib/auth/templates/home.html (Source does not exist)
Traceback Switch to copy-and-paste view
/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py in inner
response = get_response(request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = self.process_exception_by_middleware(e, request) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/robertromulus/pythonProjects/newword/newword/newword/views.py in home
return render(request, 'home.html', {}) ...
▶ Local vars
/usr/local/lib/python3.7/site-packages/django/shortcuts.py in render
content = loader.render_to_string(template_name, context, request, using=using)
I want the home.html to be rendered when I go to the root path of the site.
Problem solved - I need to add another folder then templates, and under templates each html file. This video helped. https://www.youtube.com/watch?v=xp_N4JnxHIk&t=184s&list=PLhTjy8cBISEpXc-yjjSW90NgNyPYe7c9_&index=6
Related
I’m trying to integrate Netlify CMS to a static Pelican website.
I can’t seem to access /admin as I get the following error:
Error: Failed to load config.yml
Check your config.yml file.
Here is the content of admin/index.html (I followed these instructions)
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Content Manager</title>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
<!-- Include the script that builds the page and powers Netlify CMS -->
<script src="https://unpkg.com/netlify-cms#^2.0.0/dist/netlify-cms.js"></script>
</body>
</html>
and here is the content of my config.yaml
backend:
name: github-getaway
branch: master
media_folder: "img/uploads" # Folder where user uploaded files should go
public_folder: "uploads"
collections: # A list of collections the CMS should be able to edit
- name: "post" # Used in routes, ie.: /admin/collections/:slug/edit
label: "Article" # Used in the UI, ie.: "New Post"
folder: "content/news" # The path to the folder where the documents are stored
format: markdown
sort: "date:desc" # Default is title:asc
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string", tagname: "h2", class: "entry-title"}
- {label: "Body", name: "body", widget: "markdown"}
meta: # Meta data fields. Just like fields, but without any preview element
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Category", name: "category", widget: "string", default: "News"}
if needed, the website’s url is https://distracted-engelbart-20e42f.netlify.com
Any ideas on what I’m doing wrong here?
This post is a few months old so I guess you got this working?
I had to add the admin files to the STATIC_PATHS variable in pelicanconf.py
STATIC_PATHS = [
'admin/index.html',
'admin/config.yml',
'images',
'extra'
]
Here's my example repo with Netlify CMS integrated https://github.com/marcus-clements/pelican-netlify-cms
I have an Elixir/Phoenix application in which I use brunch and npm. Since all css files are compiled into app.css and I want to not compile them all but only some of them, and include ones that aren't compiled manually on certain pages, I wonder, is there any way to do that?
In a brand new Phoenix 1.2 app, here's how to setup /css/app.css to contain all files except web/static/css/foo.css and web/static/css/bar.css, /css/foo.css to contain only web/static/css/foo.css, and /css/bar.css to contain only web/static/css/bar.css:
Modify brunch-config.js's stylesheets: object to the following:
...
stylesheets: {
joinTo: {
"css/app.css": [/^web\/static\/css\//, "!web/static/css/foo.css", "!web/static/css/bar.css"],
"css/foo.css": "web/static/css/foo.css",
"css/bar.css": "web/static/css/bar.css"
},
order: {
after: ["web/static/css/app.css"] // concat app.css last
}
},
...
Then, in the views, you can include these files separately like this:
<link rel="stylesheet" href="<%= static_path(#conn, "/css/app.css") %>">
<link rel="stylesheet" href="<%= static_path(#conn, "/css/foo.css") %>">
<link rel="stylesheet" href="<%= static_path(#conn, "/css/bar.css") %>">
I am using browserify to move a reusable typescript module into the browser using gulp.
gulp.task("default", function(){
return browserify({
basedir: '.',
debug: true,
require: ['./src/common/common.ts'],
fullPaths: false,
cache: {},
packageCache: {}
}).plugin(tsify)
.bundle()
.pipe(source('common.js'))
.pipe(gulp.dest("dist"));
});
To my surprise I need to include the resulting common.js file via
require("c:\\Users\\Luz\\Desktop\\tstest\\client\\src\\common\\common.ts");
In typescript or in builds using UMD + require JS I require files using relative paths without problems with exactly the same code. In the moment I add browserify I get absolute paths. I tried compiling typescript myself and use browserify without tsify but it always demands an absolute path to include it. All other modules that require common.js will fail to find it. How can I fix this?
Edit: Example how it looks like in the html file:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="common.js"></script>
</head>
<body>
<script>
console.log("script started");
//works
var test = require("c:\\Users\\Luz\\Desktop\\tstest\\client\\src\\common\\common.ts");
test.printCommon();
//fails (all other modules will try to find it at this path)
var test2 = require("../common/common");
test2.printCommon();
</script>
</body>
</html>
While I couldn't find the root of the problem I found a solution that works:
var brofy = browserify({
basedir: '.',
debug: true
});
brofy.plugin(tsify);
brofy.require("./src/common/common.ts", { expose: "../common/common" });
brofy.bundle()
.pipe(source('common.js'))
.pipe(gulp.dest("dist"));
The property expose will make sure that require("../common/common") leads to the correct module avoiding any absolute paths and allowing me to use the same paths I use in typescript.
Other bundles can reference the bundle using "brofy.external("../common/common");" to tell browserify to not include it in their own bundle and rather use require to find it.
Edit: Still hoping someone comes up with a better solution.
Gruntfile.js content:
grunt.initConfig({
connect: {
server: {
options: {
port: 5005,
base: '.'
}
}
},
qunit: {
all: ['test/*.html']
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.registerTask('test', ['connect', 'qunit']);
Test/index.html file content:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Sitejson - QUnit Test Runner
</title>
<link rel="stylesheet" href="libs/qunit/qunit.css" type="text/css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="libs/qunit/qunit.js" type="text/javascript"></script>
<script src="testcases/tests.js" type="text/javascript"></script>
</body>
</html>
tests.js content:
QUnit.test("hello test", function(assert) {
assert.ok(1 == "1", "Passed!");
});
I am working on Ubuntu / Linux environment. I have also installed Phantomjs and is working fine. Whenever i try to run grunt test I'm receiving a fatal error: spawn ENOENT error.
whereas i try running it on browser its qunit is working fine...
I am not able to identify what the issues. Am i missing some more configuration over here.
grunt test --debug shows me:
Running "connect:server" (connect) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-connect/tasks/connect.js
Started connect web server on http://0.0.0.0:5005
Running "qunit:all" (qunit) task
[D] Task source: /media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/tasks/qunit.js
Testing test/index.html [D] ["/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/node_modules/grunt-lib-phantomjs/phantomjs/main.js","/tmp/1405775714604.2773","test/index.html","{\"timeout\":5000,\"inject\":\"/media/hegdeashwin/Storage-TB/qunittesting/node_modules/grunt-contrib-qunit/phantomjs/bridge.js\",\"urls\":[],\"force\":false,\"console\":true,\"httpBase\":false}"]
Fatal error: spawn EACCES
Use the following process:
set the tmpdir environment variable:
setenv TMPDIR=~/tmp
Rerun the grunt task
If it works, set this permanently by adding the following to your .bashrc or .profile:
export TMPDIR=~/tmp
References
Troubleshooting · npm/npm Wiki
Secure Programs HowTo
Environment Variables
FAQ Troubleshooting
I'm currently trying to incorporate GruntJS with a few plugins (PhantomJS Qunit and Connect plugins). However, setting up a simple test is throwing me errors and I can't find the solution despite a few days of searching. I'm using a local web server (MAMP) and the website is running on a CMS.
Running the tests by accessing the test template in a browser works fine, but when trying to access the same tools via the command line using sudo grunt test PhantomJS return an odd error:
Running "qunit:all" (qunit) task
Testing http://user-guides:80/test/test.html
Warning: PhantomJS timed out, possibly due to a missing QUnit start() call. Use --force to continue.
Aborted due to warnings.
Some of my searches had people downgrading their version of phantom.js to deal with similar problems, but so far none of those solutions have worked for me, and I'm afraid i'm missing something right in front of my face.
Here's the contents of my Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
hostname: 'user-guides',
port: 80,
base: 'public'
}
}
},
jshint: {
all: ['Gruntfile.js', 'public/assets/js/helper/*.js', 'public/assets/js/specific/*.js']
},
qunit: {
all: {
options: {
timeout: 5000,
urls: [
'http://user-guides:80/test/test.html',
]
}
}
}
}
);
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('test', ['connect', 'qunit']);
};
Here's the simple Qunit test
<html>
<head>
<meta charset="utf-8">
<title>Tests</title>
<link rel="stylesheet" href="/assets/lib/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="/assets/lib/qunit.js"></script>
<script>
console.log("====TEST===");
start();
test( "hello test", function() {
ok( 1 == "1", "Passed!" );
});
</script>
</body>
</html>
Any help is greatly appreciated.
In my test.html file I originally had just copied the example from the QUnit Cookbook
After finding a similar (possibly the same) issue here:
https://stackoverflow.com/a/25053808/1814739
I updated:
<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>
to:
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>
Running from command-line seems to work after adding http: to the src attribute.