I have a new project for a little online shop. I use the PyCharm code editor. It saves the progress whenever I switch to a new window and the server autorestarts. After a while of working on the project the server stopped doing that and now it needs to be done manually. When I got to making forms, I noticed that they don't show on the page. It's the same logic as in my previews projects. I made exactly the same forms and models from the old project in the current one and they do not work. Then I did the opposite: I added the models and the form from the current project into the old one and they do render on page.
What could be the problem and where shoul I start looking for it?
Related
So I made a django app and deployed it using Heroku - with s3 for file uploads and whitenoise for static files. I use the admin page to add updates to the displayed sections, like new blog entries (for example or comments).
The problem is that any database update using the admin page stays for a day at most and then refreshes, going back to the previous state and making me lose all the new data.
I have tried some stuff, but I am totally out of my depth here. I even tried pulling the changes made back into my local copy and pushing again to repository but it shows no changes. Is it something to do with how Django takes in user input? If anyone could help me that would be amazing. If you guys need any code please tell me.
I'm making a simple file resizer with Django, there are 3 fields, email, size, image.
After the user arrives to a the last view where he can download what he resized, I'd like Django to erase the image of the ImageField to save space on my Django project whenever an user close his window with the final view page.
I do want to keep the email and the size as it is, so these are the only things that shouldn't be deleted.
I have no idea where to search, I looked into StackOverflows posts and in Django google groups articles but I could not find something to help me, any suggestion on how this can be done ?
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunload - you can try using this method to handle browser close tab with js and send request to django.
But in your place I would prefer timeout after which all images resized certain time ago would be removed (it can be done with simple cron script, possibly with some management command).
I have 2 apps which i would like to combine, the first one is a login & register system and the next one is a file upload system how would i go by combining them?
This is a very specialized question that depends heavily on the code contained within them. Assuming they are set up as two separate forms in their own views, you may be able to put two separate forms on the same page but without seeing the code, screenshots, design plans or anything of the like, this is a very difficult question to answer.
I would like to have commented this instead, but I don't have the rep. Sorry for not actually answer the question.
There are many ways to do this and it would all depend on how your project is setup. Normally when you create a project in django you are forced to create an app, this is for modularity, the idea is to be able to have the apps be self contained entities, so in your case, you may want to move the app itself (not the project) from the upload system to your main login & register app, so just move / copy the "app" folder over to your other project, then you will also need to copy the settings and move them over. You also need to update the urls.py in your main app to include the urls from your second app.
Anyways this should give you some hints on how you could do this.
I'm learning Django but it's difficult to me to see how should I divide a project into apps?
I've worked on some Java EE systems, almost for procedures for government and all that stuff but I just can't see how to create a Django project for this purposes?
For example, if you should have to do a web app for making easier three process: Procedure to get the passport, procedure to get the driver license and procedure to get the social number.
The 3 procedures have steps in common: Personal information, Contact Information, Health Information. Would you do a project for each procedure, an app for each procedure, an app for each step?
I'm sorry if I'm posting this in the wrong Stack Exchange site.
Thank you.
When you say "procedures" i guess you're talking about pages (or views in Django). So I would implement a single "app" to do that.
Remember a project is composed of apps. When you create a project a main app (with the same name of the project) is created. This is a good place to code the procedures you said.
Think of apps as indepent sections of your project (site); maybe some forum, a blog, a custom administration panel, a game and stuff like that. Every one of them could be an independent app.
A project is mostly intended as a single website, so there's no need to create another project on the example you mentioned.
I have a new job and a huge django project (15 apps, more than 30 loc). It's pretty hard to understand it's architecture from scratch. Are there any techniques to simplify my work in the beginning? sometimes it's even hard to understand where to find a form or a view that I need... thnx in advance.
When I come to this kind of problem I open up a notebook and answer the following:
1. Infrastructure
Server configuration, OS etc
Check out the database type (mysql, postgres, nosql)
External APIS (e.g Facebook Connect)
2. Backend
Write a simple description
Write its input/output from user (try to be thorough; which fields are required and which aren't)
Write its FK and its relation to any other apps (and why)
List down each plugin the app is using. And for what purpose. For example in rails I'd write: 'gem will_paginate - To display guestbook app results on several pages'
3. Frontend
Check out the JS framework
Check the main stylesheet files (for the template)
The main html/haml (etc) files for creating a new template based page.
When you are done doing that. I think you are much more prepared and able go deeper developing/debugging the app. Good luck.
Use this http://packages.python.org/django-extensions/graph_models.html
to generate the Relationship diagrams from the models so that you can visually see how the models are related to each other. This will give you nice idea about the app
1) Try to install the site from scratch. You will find what external apps are needed for the site to run.
2) Reverse engineer. Browse through the site and try to find out what you have to do to change something to that page. Start with the url, look up in urls.py, read the view, check the model. Are there any hints to other processes?
3) Try to write down everything you don't understand, and document the answers for future reference.
I would clone the project so you can mess up endlessly.
Then I would start to reduce the code. "What happens if if just remove this function here?
Also get django debug toolbar:
https://github.com/django-debug-toolbar/django-debug-toolbar
A good terminal debugger is also golden, there are many out there, here is an example:
https://github.com/tomchristie/django-pdb
This allow you to halt the code and even inject and mutate parameters in runtime. Just like GDB in C.
If you use FireFox you can install FireBug on it and when you for example submit ajax form you can see at which url send you request after what you can easily find controller which work with this form data. At chrome this utility embedded by default and call by F12 key.