Hello
I have recently completed python course, i can rate me 6.5 in python out of 10. And now I'm looking to get my hands on django framework, i want a job as a python intern. Courses in udemy are bit complicated i don't know, i just want to learn n do some projects in django but also with that it's good if you can find me a course where I can also revise my python again in the same course. In short i want python+ django course But please suggest me that course where I can learn orm, api in django in udemy.
Hello
But I'm a newbie in django
Muflone
do you want to remain newbie?
Prakhar
Any idea on writing unit tests for django, specifically when you have to login before using the application.. I have done it for basic apps.. But want to have a clear understanding on how to do it in a complex application where login page has username, password and captcha.. Please dont forget to tag me in your answers.. Thanks..
ㅤㅤㅤㅤ𝗹𝗼𝗿𝗱ㅤㅤㅤㅤㅤ
Cookies in session management
Cookies contain login, credentials ( session is like how much time you spent on site .
Xusrav
Hi guys, how are you think, tests cases must important for Django?
Charly
Hi guys, how are you think, tests cases must important for Django?
For any kind of software tests nar fundamental to ensure some level of quality
Xusrav
totally yes
For small projects too much?
Alex
For small projects too much?
If it requires to be deployed or used then yes
cj
For small projects too much?
even if you write one line of code, yes
Prakhar
You can test the login and mock the captcha response (to test the login for successful and unsuccessful cases)
Thanks for your response @christian_mtr , have tried this using the Client class in django test modules... Seems to be working..
Georg
is there a way to create "in-memory" queryset ? is there an interface to implement that ?
Doragonsureiyā
is there a way to create "in-memory" queryset ? is there an interface to implement that ?
To get an answer to your question, it is worth to formulate it more clearly, perhaps add more details, perhaps add explanations.
Maxim
is there a way to create "in-memory" queryset ? is there an interface to implement that ?
what do you mean ? what's wrong with a "normal" queryset ?
Georg
sometimes I need to hold my data locally, in memory (not in database) but I want to have a QuerySet interface to manage it
Maxim
sometimes I need to hold my data locally, in memory (not in database) but I want to have a QuerySet interface to manage it
It depends on whether you only want some data or you want all the operations available with the QuerySet
nishaj
Is anyone know how to deploye chat app using redis and daphne
Erkaboy
Hi all. I have a django project. inside django project I have an app called app. and I have custom folder for bot called bot which is in the same level with app. I have got a problem import app.models inside bot folder. How can i do that. I have tried relative import and tried to add app folder to sys.path. Anyone know solution?
John Doe
Hello, everyone who knows how to correct this error? 'AnonymousUser' object has no attribute '_meta'
Erkaboy
Erkaboy
Do you have __init_ _.py
Yeah I have. In both folders.
Axror
so, you need to add os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_app.settings') bot main file
Muflone
Hello, everyone who knows how to correct this error? 'AnonymousUser' object has no attribute '_meta'
You're reading something from the user while the user is not yet logged in
John Doe
You're reading something from the user while the user is not yet logged in
The thing is, I dont have @login_required in my visualization: https://pastebin.com/zEQ4WiqX
Muflone
ERMIA
Yeah I have. In both folders.
Imported bot in installed app?
ERMIA
The thing is, I dont have @login_required in my visualization: https://pastebin.com/zEQ4WiqX
But you should check if user.is_authendticated cuz it might be base tampleate or so
Erkaboy
Imported bot in installed app?
I have added it to installed apps. But I am not sure If I have done it correctly or not.
ERMIA
I have added it to installed apps. But I am not sure If I have done it correctly or not.
Ans also app folder? When you call the name of app app Then it extends AppConfig to AppConfig i think & might cuz error Have you tried app.apps.AppConfig?
Anil
How can I learn the Rest API in an easy manner?
Doragonsureiyā
How can I learn the Rest API in an easy manner?
Are you looking for Django REST Framework documentation? Here you have it: https://www.django-rest-framework.org/
Manoj
Media files are not showing at the site
Manoj
what might be the problem?
cj
what might be the problem?
in production? then you didn't configure the server for static/media files correctly in your web server in development? check and double check your settings file
Manoj
STATIC_URL = '/static/' MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR / 'media'
Manoj
this is the code in settings.py file
Axror
Should I use this inside a file which I am importing models?
Yes, you should add it and you can use django modules easly
Manoj
this is the code in settings.py file
and the code media directory is at the level of innerproject
Manoj
it is working file on localhost
Manoj
but not on pythonanywhere
Muflone
but not on pythonanywhere
Is debug off? Did you set the Path in python anywhere for static files?
Manoj
Is debug off? Did you set the Path in python anywhere for static files?
yes i have, other static files are working fine except the files which are inside the media directory
Manoj
you can check the site http://meroshopping.pythonanywhere.com/
Muflone
yes i have, other static files are working fine except the files which are inside the media directory
I cannot remember Does PA allows you to set multiple paths, one for /static and the other for /media?
Asad Ullah
what is the diff between app_name and app_label?
Muflone
what is the diff between app_name and app_label?
app_name is used in urls only app_label is the app name used everywhere
Aditi
Any one have django course?
Doragonsureiyā
Any one have django course?
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Aditi
Okay, thanks
Aditi
Any video lecture course for beginners?
JuanSe
Any one have django course?
At coursera, a specialization in back-end by Meta
Charly
Any video lecture course for beginners?
Go for official turotial first. Its the best thing to do. Vuideos often show you superficial things only.
Mendux
Is there a more elegant way to override the DEFAULT_AUTHENTICATION_CLASSES ? This is what I have implemented. https://linkode.org/#DXA3C50na6Jxr2gYmuhKG1 Although it is working, I feel like there is a more elegant way to do it.
Anonymous
Hello, which is the best preferred way for server side rendering when working with Django but also want to use react for frontend
cj
Hello, which is the best preferred way for server side rendering when working with Django but also want to use react for frontend
configure your webserver (apache, nginx, etc) to serve static files (css, js, images and other media) and when you have your frontend project ready (read is as "compiled" in js files) serve it as any other static file. don't serve static files from the backend app side
Mendux
please no
lemme share my approach on this on package.json { "name": "app_name", "proxy": "http://localhost:8000", ..., "scripts": { ..., "build": "rm -rf ../backend/build && react-scripts build && cp -r build ../backend/", ... }, }
Mendux
settings.py INSTALLED_APPS = [ ..., build, ... ] TEMPLATES = [ { ..., 'DIRS': [ os.path.join(BASE_DIR, 'build'), ], .... ] STATIC_FILES_DIRS = [ ..., BASE_DIR / 'build/static' ] urls.py from django.views.generic import TemplateView from django.urls import path, re_path urlpatterns = [ ..., re_path(r'^.*', TemplateView.as_view(template_name="index.html")) # frontend ]
Mendux
It's not about able to do it, is about not doing it because it's wrong
why? its basically serving the frontend as static files
Mendux
you shouldn't do that, you'd better learn some DevOps things and serve static files in the proper way
what's the harm of that implementation? I mean, at the end of the day, the build dir will always serve as static files. once you run collectstatic, it'll get collected to whatever server you are using to server your static files.
Mendux
since the frontend js/css will have been bundled in the 'static' dir in the build folder
Anonymous
Guys I wanna develop e-commerce project with DRF, ReactJS, HTML, CSS together. But, I wonder about integrating Django Rest Framework with ReactJS front-end through Axios. Someone explain this concept, how to do that?
Mendux
Guys I wanna develop e-commerce project with DRF, ReactJS, HTML, CSS together. But, I wonder about integrating Django Rest Framework with ReactJS front-end through Axios. Someone explain this concept, how to do that?
I happened to have just explained that. Though @c0x6a has a problem with my implementation. I'm still waiting for his reply on why I shouldn't implement that.
Mendux
settings.py INSTALLED_APPS = [ ..., build, ... ] TEMPLATES = [ { ..., 'DIRS': [ os.path.join(BASE_DIR, 'build'), ], .... ] STATIC_FILES_DIRS = [ ..., BASE_DIR / 'build/static' ] urls.py from django.views.generic import TemplateView from django.urls import path, re_path urlpatterns = [ ..., re_path(r'^.*', TemplateView.as_view(template_name="index.html")) # frontend ]
In case you are still in development and are still using port 3000 for the frontend, add the cors-headers configuration to the settings.py by adding proxy in package.json, you should be able to do API calls to the API using the endpoints only, for example: const response = await axios.get("/api_endpoint")