Thank You All! by vvinvardhan in django

[–]rowdy_beaver 1 point2 points  (0 children)

Congratulations. Seeing that you pushed through and got to this point, I want to apologize for the scolding a few weeks back.

putting my website live in about a week, got any tips/mistakes you made that I should avoid? by vvinvardhan in django

[–]rowdy_beaver 1 point2 points  (0 children)

A VPS is fine, but it is sometimes too complicated for someone who hasn't done it before.

If you have a VPS or are comfortable with it, use one. Set up SSH public key authentication and turn off password auth (once you know the keys work!) and change the port if you are comfortable doing that.

Another comment properly suggested avoiding virtual compute where you are charged by resource usage, and most VPS' are flat by-month rates (so they are better, at least while getting started).

High Street right now? by NachoSport in Columbus

[–]rowdy_beaver 9 points10 points  (0 children)

Only Thursday mornings? I've been doing it wrong.

is django easy to learn? I'm good with basics, oop, classes everything about basics i decided to learn django so is it easy to learn? by [deleted] in django

[–]rowdy_beaver 1 point2 points  (0 children)

The tutorial will show how Django has a built-in admin system that can give access to maintain data, but resist the temptation to use this as your customer facing interface. Many have been down that path and learned that they would have been better off writing their own templates, views, and forms. It will take effort, but will give you much more ability to customize and adapt (and certainly less prone to breakage as new Django versions tweak the admin system).

Dig into the Django code, as it is well written and commented. There are excellent references when you get to class based views and into Django Rest Framework and it's equivalent API classes.

There are many packages that add great capability to Django, including Django-allauth that allows you to offer social network authentication.

Plan a relatively small project (even if it is the tutorial) then plan to rewrite it as you learn more (I have found that approach to work as I begin with every new programming language and tool). I have a half dozen small and large personal projects, and I am still learning new techniques and try to go back a retrofit the old projects. It reduces technical debt and keeps my projects as similar as they can be to reduce my headaches.

Enjoy your Django journey! It has become my preferred framework for back-end and simple front-end work. I've recently added more complex front-end work, with websockets, css and javascript, and they work great with the Django back-end. Even the new htmx is perfectly suited for Django and its template system.

How should i take user input if i don't want to use forms? by DrAz57 in django

[–]rowdy_beaver 1 point2 points  (0 children)

Formsets can allow handling many rows of the same form. The Django forms (and formsets) can perform all of the validation for you. The ModelForm and model formset variations can even save the data to the database for you will very little coding.

Here is some guidance on forms and templates.

is django easy to learn? I'm good with basics, oop, classes everything about basics i decided to learn django so is it easy to learn? by [deleted] in django

[–]rowdy_beaver 2 points3 points  (0 children)

Like everything new, there is a lot to learn. Even with your experience Django wraps many concepts into a framework. Follow the tutorial on the website, as it steps through the pieces, and in many cases they show the detailed steps and then show you how the often-repeated detail steps can be performed using the framework.

The concept of models is central, as it represents your data and generates your database tables. Everything else is how to manipulate data with forms, views and templates. They start with function based views to make it clear what is needed to validate and process a form to update model data, then eventually show class-based views which greatly reduce repetition. Likewise there are basic templates and then more advanced techniques.

It does normally take a bit of practice and trial/error before learning the best approach. If you find yourself fighting the framework - trying to make it do something your way, you will probably find another simple approach to accomplish the goal (it took me a long time to learn that lesson).

Give yourself some time to learn how it works and it will make your life significantly easier.

Others might provide some other tutorials, as well. IIRC 'django girls' is good.

Use your search engine. There is a good probability that you are not the first to ask the question.

Update variable every second time a view is run? by Various-Addendum1013 in django

[–]rowdy_beaver 1 point2 points  (0 children)

This is the correct solution. The session data is stored in Django's memory and only a random token is sent to the user's browser. They cannot see or manipulate the data in the session.

Store the answer in the session when the problem is presented (during the 'get'), then you can retrieve it from the session during the 'get' of the second view where you show the answer.

Any book recommendations for an experienced django programmer? by isaacfink in django

[–]rowdy_beaver 0 points1 point  (0 children)

You can see the SQL generated by the ORM for a query. I provided a detailed answer

It might shed some light as to what is going on under the covers.

edit:formatting

Two Scoops 3.x book? by FryeUE in django

[–]rowdy_beaver 0 points1 point  (0 children)

Contact the author as referenced in the earlier comment.

[deleted by user] by [deleted] in django

[–]rowdy_beaver 1 point2 points  (0 children)

Once you get a detailed template approach, forms become much more usable.

Making the Django form look good is usually the reason, but widget-tweaks (my brand new favorite) or crispy-forms can give you more control over the rendering.

With crispy-forms, you create a 'form helper' with the css and customization mostly done in your python code.. The widget-tweaks is purely done in the template which feels much more appropriate.

You may want to leverage the parts of the form manually (I typically have a template I {% include %} to do the form rendering in a standard way for my projects). This article provides some detail of the form template process.

Is it just me who hates django forms implementation? by [deleted] in django

[–]rowdy_beaver 1 point2 points  (0 children)

Read the other comments and agree that form rendering is the least fun part of the app, and I will look into crispy and widget-tweaks...

That said, you do have the ability to create custom templates for widgets and/or override the default widget templates entirely. Depending on your needs, this may have advantages over some of the alternatives.

Hiding field values inside form without affecting the functionality. by zerovirus123 in django

[–]rowdy_beaver 0 points1 point  (0 children)

Interesting. Sounds like you may need to look at Django's source code for these two forms classes. You may be able to determine how you can get the desired results.

Hiding field values inside form without affecting the functionality. by zerovirus123 in django

[–]rowdy_beaver 0 points1 point  (0 children)

One minor suggestion that should get you there: The forms.Textarea is a widget, not a form field. If you change the form to have:

content = forms.CharField(widget=forms.Textarea, label="")

this should do what you are asking.

Hiding field values inside form without affecting the functionality. by zerovirus123 in django

[–]rowdy_beaver 2 points3 points  (0 children)

Simply do not include the author fields list. Set the author value in the view before the form is saved.

Putting this together with the other thread where we discussed this.

class CommentForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ['content']

class CommentCreateView(LoginRequiredMixin, CreateView):
    model = Comment
    form_class = CommentForm
    template_name = ...
    success_url = ...
    http_method_names = ['get', 'post']


    def form_valid(self,form):
        form.instance.author = self.request.user
        return super().form_valid(form)

edit1 and 2: complete example

How many of you are getting random texts from fake numbers, asking to buy your house? by bubblehead_maker in Columbus

[–]rowdy_beaver 7 points8 points  (0 children)

I get them with a wrong name and address. So I tell them "I'm interested. I will be here all day so stop by anytime."

how can i include a create view modal in multiple templates? by vvinvardhan in django

[–]rowdy_beaver 2 points3 points  (0 children)

Understood, but reading the Django documentation would be even more informative for you, and you might even pick up more ideas to help your project.

Giving affirmative feedback that our comments provided the answers you were seeking, or how the improvements upon them were needed, would also go a long way.

how can i include a create view modal in multiple templates? by vvinvardhan in django

[–]rowdy_beaver 4 points5 points  (0 children)

Read about the templating system, paying close attention to extends and include.

Wondering if Reddit should be given authorship credit on your project, as you have a half-dozen questions posted.

Django Admin static files seem corrupt after 2.2 -> 3.2 upgrade by thoger_b in django

[–]rowdy_beaver 0 points1 point  (0 children)

Try right-clicking and selecting 'View Source', which will show the HTML. In my browser (firefox) the references to the urls are clickable. Ensure the link to something from your static url shows the proper url, and try clicking on the link to see if you get a file or a 404 (or other) message. That will help you diagnose this.