George
hi what software/library do you recommend for automatic pdf generation (in Django obviously)?
George
Ok
Maz
Lol...the whole package site has nothing on pdfs??
George
NO THING
George
but i found some old packages that i don't need
Maz
Well, that's a first 😅 Although I meant the actual site....not the github repo.
R
hi what software/library do you recommend for automatic pdf generation (in Django obviously)?
Weasyprint converts html to pdf and is really easy to use, but it has few dependencies and I found some limitations which I ended up solving with ReportLab which is a bit harder to use but works quite nice
R
Not used it, so can’t compare with options I mentioned :)
George
ok, i'll try whatever this afternoon
Maz
MMMMM i also thought of xhtml2pdf.pisa
Recommend that you use something that guys use a lot in their projects...using some obscure package means it will be harder finding help if your app breaks
Maz
@Inchidi can advise
Anders (izzno / gooood) πŸ‡³πŸ‡΄
Do you guys build in the main project name or do you make apps for everything and mostly leave the projecname/samename dir alone ?
Mirco
Do you guys build in the main project name or do you make apps for everything and mostly leave the projecname/samename dir alone ?
Read ( if you haven't already done it ) what pydanny suggests about project structure inside 2 Scoops of Django
Anders (izzno / gooood) πŸ‡³πŸ‡΄
I did, but the thing is the front page, it pulls information from many apps, so I am wondering if I should create a "frontpage" app or Site or what ever to put the "about" "faq" and so on or just throw it in the "main" dir
Mirco
Mmm I don't think that's an app It's just a template
Anders (izzno / gooood) πŸ‡³πŸ‡΄
That needs a view ;)
Anders (izzno / gooood) πŸ‡³πŸ‡΄
dilemmas... Ill use the "main" and move it if it becomes more than views ...
Mirco
That needs a view ;)
Yep but just a TemplateView You could put it into main urls file imho
Anders (izzno / gooood) πŸ‡³πŸ‡΄
Yep but just a TemplateView You could put it into main urls file imho
How will i get the data I need from the models?
Mirco
Ah ok I didn't understand you need data , sorry 😅
Anders (izzno / gooood) πŸ‡³πŸ‡΄
haha, thats fine ;) Everything is dynamic hehe.
Anders (izzno / gooood) πŸ‡³πŸ‡΄
But as long as I am just gathering data i dont think its messy to ue the "main app".
Mirco
I'd create a specific app if I plan to reuse it etc. etc.
Anders (izzno / gooood) πŸ‡³πŸ‡΄
hm, maybe...
Sebastian
Hi guys :) I've got a testing problem. I test with Client() if I want to control my context dictionary, my view creates. (response.context) Here I can not put a User in the request. So no function in the view function can get the user I need to get. (?) // And I test with RequestFactory() if I want to put a User in my "request" which I can put in my view function. Unfortunately with RequestFactory() I can not controle any context dictionary. Does anybody have a good practice how I can put a user in the request as well as control the generated context of my view-function?
inchidi
Do you guys build in the main project name or do you make apps for everything and mostly leave the projecname/samename dir alone ?
maybe this will help you, this is how my django project structure usually looks like https://gist.github.com/DimasInchidi/d3c534bdb2362aca295d3e75a95b288f
Sebastian
## View: def viewName(request, x_ID): pass user_ID = request.user.id context_DIC = {'contextKey': 'contextValue', 'user_ID':user_ID} return render(request, 'xxx.html', context_DIC) ## Testcase: @pytest.mark.django_db(transaction=True) def test_x(): user = User.objects.get_by_natural_key(username='Testuser2@xxx.com') url = reverse('appName:viewName', kwargs={'x_ID': 1}) request = RequestFactory().post( path = url, data=context_DICT, ) request.user = user response = viewName(request, x_ID=1) assert response.context_data['contextKey'] == 'contextValue'
Sebastian
This is my code. And this is the error:
Mirco
Use pastebin pls or dpaste
Sebastian
assert response.context_DIC['xxx_STR'] == 'xxx' AttributeError: 'HttpResponse' object has no attribute 'context'
Mirco
It's easier to read
Sebastian
Oh ok. I try to do that^^ One moment.
Sebastian
https://pastebin.com/GuCdymmy
inchidi
assert response.context_DIC['xxx_STR'] == 'xxx' AttributeError: 'HttpResponse' object has no attribute 'context'
if this exactly how the error you get, then i think you are sharing wrong piece of your code
Sebastian
I tryed to alienate the code a little bit. I'll do it better. I'll send a new pastebin snipped which works.
Sebastian
https://pastebin.com/25Kp8Jfh
Sebastian
I have run the snipped and it raise now exactly the error which is also in the snipped.
Anonymous
i give redirect to home if login success but it redirects to login page can't figure out here is the code
Anonymous
can't login with correct id,pwd
Mr. Rude
Try putting print statements
Mr. Rude
And debug
Mr. Rude
Try to print user
Mr. Rude
Will let you know if it is null
Anonymous
i tried but login is correct or incorrect it won't do any process just refresh the login page
Mr. Rude
Is the user null?
Mr. Rude
What happens when you print user
Anonymous
if user == 'isnull': print(user) else: return redirect('home')
Anonymous
redirect home
George
LOL https://weasyprint.readthedocs.io/en/latest/install.html#windows
George
I am going to use weasyprint for pdf generation and im reading the docs "Of course you can decide to install ancient WeasyPrint versions with an erstwhile Python, combine it with outdated GTK+ libraries on any Windows version you like, but if you decide to do that you’re on your own, don’t even try to report an issue, kittens will die because of you."
Milan
Try pip install django to install latest version
Milan
Then your python version is 2.7
Milan
Please try to install django with python3
⚘
i can't install the latest version of Python, neither Python3 nor Python2, please help
Anonymous
Check the active environment
Milan
pip3 install django
Milan
MyNotes/Python.md at master · milankathiriya/MyNotes · GitHub https://github.com/milankathiriya/MyNotes/blob/master/Python.md
⚘
pip3 install django
command not found 😐
Milan
@m3rrym4n_h4ck3r
Milan
MyNotes/Python.md at master · milankathiriya/MyNotes · GitHub https://github.com/milankathiriya/MyNotes/blob/master/Python.md
Anonymous
You better to install all the setup config inside the environment and save to the file requirements.txt file by using the pip freeze > requirements.txt
Anonymous
Command
George
hi, i am creating a pdf from html but it wont download when i click the button
Milan
hi, i am creating a pdf from html but it wont download when i click the button
Maybe an attribute called 'download ' must be in button tag to do that
George
no
Milan
wat
w3schools.com/tags/att_a_download.asp
George
i downloaded a file without that atribute
George
i execute an ajax call
George
you didn't even let me explain xD