Errno 22 Invalid argument \\:\\ added - django

I am exporting a django project from a computer that runs Ubutnu to another that runs Windows 10. I've exported the environment with pip install -r requeriments.txt and everything seems to work fine, since, for example, python manage.py migrate is working properly.
The server starts fine with python manage.py runserver, however, when I open the URL http://127.0.0.1:8000/home in my browser I get the following error:
IOError at /home/ [Errno 22] Invalid argument:
u'C:\Users\myusername\Envs\myenv\myproject\:\HomePage.html'
The views are correctly setup because the project was running OK in ubuntu. The problem seems to be that the HomePage.html, which is supposed to be located in ...\\myproject\\marketingApp\\templates\\HomePage.html, is being looked for in ...\\myproject\\:\\HomePage.html and I don't know how/where to fix that.

I managed to load http://127.0.0.1:8000/home by adding my project folder path 'C:\\Users\\myuser\\Envs\\myenv\\myproject' directly into the TEMPLATES dict:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
'C:\\Users\\myuser\\Envs\\myenv\\myproject'
],
'APP_DIRS': True,
'OPTIONS': {
'debug':DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz"
],
},
},
]

Related

PyCharm - Auto-reloading Django dev server after template changes

How to make my PyCharm to reload Django dev server after i make changes in templates?
It reloads on save on every other changes but not for template changes.
server is starting by docker compose up
We are using Django 3.2.16
entrypoint.sh:
exec gunicorn app.wsgi:application --config gunicorn.py --reload
settings.py
[...]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"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",
"app.context_processors.get_version",
"app.context_processors.get_env",
]
},
}
]
[...]

Unit testing in browser for NativeScript fails because of .tns. files

I have an Angular flavoured Nativescript project, which must be tested with "vanila" Jasmine, in a browser (so not in mobile) with ng test.
By default, with "naked" tests, it works. But the problem is, if I try to test/import anything, that has a ".tns" alternative, in some cases it loads that, and the build fails.
My problem is similar to this thread but there were no good solution described there.
So for instance:
I have two files:
app.component.tns.ts
app.component.ts
and I try to import it for testing in app.component.spec.ts:
import {AppComponent} from "#src/app/app.component";
it loads the .tns. file, and the build fails, as it cannot load the mobile-specific libraries.
ERROR in ./src/app/app.component.tns.ts
Module not found: Error: Can't resolve 'nativescript-ui-sidedrawer' in '/home/..../src/app'
resolve 'nativescript-ui-sidedrawer' in '/home/...../src/app'
Parsed request is a module
using description file: /home/...../src/package.json (relative path: ./app)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
...
# ./src/app/app.component.tns.ts 25:35-72
# ./src/app/app.module.spec.ts
# ./src sync \.spec\.ts$
# ./src/test.ts
is there any solution to "remove" the .tns. files, just as if I were running a simple ng serve?
update: My tsconfig.spec.json should exclude these files, but it does not work either ...
"exclude": [
"**/*.tns.ts",
"**/*.android.ts",
"**/*.ios.ts"
]
}
it seems the problem was with tsconfig.json. Specificly this part:
"compilerOptions": {
...
"paths": {
"#src/*": [
"src/*.android.ts",
"src/*.ios.ts",
"src/*.tns.ts",
"src/*.web.ts",
"src/*.ts"
]
},
As this was extended by the tsconfig.spec.json.
I modified the tsconfig.spec.json to this:
{
"compilerOptions": {
"target": "es5",
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"typeRoots": [
"node_modules/#types"
],
"lib": [
"es2017",
"dom",
"es6",
"es2015.iterable"
],
"baseUrl": ".",
"resolveJsonModule": true,
"esModuleInterop": true,
"paths": {
"#src/*": [
"src/*.ts"
]
},
"outDir": "../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
],
"exclude": [
"**/*.tns.ts",
"**/*.android.ts",
"**/*.ios.ts"
]
}
and now the tests run, and the correct components are imported.

django templates not found

I have already looked for almost all questions but still none of the answers is working for me. The error I get:
My BASE_DIRS = "/home/amank/Adevelopment/test/mechanical/templates"
This is okay but still django is looking in different irrelevant paths as shown in screen shot ...
My related settings:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
.
.
.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
Any method to give templates path manually in settings.py?
Traceback
PROBLEM SOLVED ..But still I don't get the reason behind it .I have posted the solution below..
Go to your main project directory, make sure you have
templates
directory inside it. Inside templates you should have home directory inside which there should be index.html
This answer is based on image provided in Question.
I got it working somehow but i even don't know how it worked...Basically
I removed this part fully
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
and replaced it with
TEMPLATE_DIRS = (
"/home/amank/Adevelopment/test/mechanical/templates",
)
It somehow worked . If anyone can explain why before it wasn't working on PC while same code is running it on internet www.me.iitb.ac.in ?

Debugging Django in VSCode fails on imp.py

I am unable to debug my Django app. I am using virtualenv and have configured my VSCode workspace to point to the absolute path within my virtual environment for python.
"python.pythonPath": "/Users/Me/PyProjs/proj_env/bin/python"
When trying to debug, however, the editor jumps to the imp.py file (which is located at ~/proj_env/lib/python3.4) and fails at the new_module() method.
def new_module(name):
"""**DEPRECATED**
Create a new module.
The module is not entered into sys.modules.
"""
return types.ModuleType(name) #Editor breaks here.
Inspecting the name variable, I see it is set to "__main__". When stepping through, the editor exits debug mode and no errors or exceptions are logged in the Debug Console.
Anybody know what my issue could possibly be? I just want to debug my application!
You probably have stopOnEntry set to true in your launch.json. Try setting it to false:
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceFolder}/manage.py",
"cwd": "${workspaceFolder}",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput",
"DjangoDebugging"
]
},
Looks like a possible defect, check the VS Code Python GitHub repo: https://github.com/DonJayamanne/pythonVSCode/issues/1092

Django CMS initial migration fail

I've gone through the installation steps on the Django-CMS site, and I am unable to do the initial migration. I keep getting the following error:
if x['BACKEND'] == 'django.template.backends.django.DjangoTemplates'][0]
KeyError: 'BACKEND'
Googling this error yields nothing. I've scoured setup.py and I'm not seeing anything like this. I'm just lost and a bit worried that the install instructions may be a bit dated, as I also had to remove the list of extra apps they suggest adding to INSTALLED APPS because none of them were found. Anyway, I'm down to this error, I think. Is anyone familiar with this?
You probably miss the 'BACKEND': 'django.template.backends.django.DjangoTemplates' entry inside the TEMPLATES setting, in your settings file. Check out https://docs.djangoproject.com/en/dev/ref/settings/#templates
Make sure that all of your entries are listed in single dictionary. For instance, if you are following along with the 'Integrating a third-party application' tutorial, when they show the following...
'OPTIONS': {
'context_processors': [
# ...
'aldryn_boilerplates.context_processors.boilerplate',
],
'loaders': [
# ...
'aldryn_boilerplates.template_loaders.AppDirectoriesLoader',
],
},
},
...you need to integrate it into your existing dictionary. Your TEMPLATES array would then look like the following:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
'django.template.context_processors.csrf',
'sekizai.context_processors.sekizai',
'cms.context_processors.cms_settings'
'aldryn_boilerplates.context_processors.boilerplate',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
'aldryn_boilerplates.template_loaders.AppDirectoriesLoader',
],
},
}
]